Last active
August 29, 2015 14:03
-
-
Save le717/d55c4dbd608cc484332c to your computer and use it in GitHub Desktop.
For my Python tutorial "Count the number of lines in a file" (http://wp.me/p1V5ge-1BK)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env/python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
numOfLines = 0 | |
with open("samplefile.txt", "rt") as f: | |
for line in f: | |
numOfLines += 1 | |
print("There are {0} lines in this file.".format(numOfLines)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is the first line. | |
This is the second line. | |
Three is a magic number. Yes it is. It's a magic number. | |
Fishing Four Fish | |
Fives are easy to count by. | |
I got six! That's all there is! | |
Too bad there is no line 0. My Hero Zero is catchier than Lucky Number 7. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment