code: def count_lines(fname, mode='rU'):
      '''Count the number of lines in a file
  
      Only faster way would be to utilize multiple processor cores to perform parallel reads.
      http://stackoverflow.com/q/845058/623735
      '''
  
      with open(fname, mode) as f:
          for i, l in enumerate(f):
              pass
      return i + f count_lines(fname, mode='rU'):
      '''Count the number of lines in a file
  
      Only faster way would be to utilize multiple processor cores to perform parallel reads.
      http://stackoverflow.com/q/845058/623735
      '''
  
      with open(fname, mode) as f:
          for i, l in enumerate(f):
              pass
      return i + 1
docs: Count the number of lines in a file
  
      Only faster way would be to utilize multiple processor cores to perform parallel reads.
      http://stackoverflow.com/q/845058/623735