Skip to content

Instantly share code, notes, and snippets.

@le717
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save le717/d55c4dbd608cc484332c to your computer and use it in GitHub Desktop.
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)
#! /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 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