code: def count_lines_in(filename):
      "Count lines in a file"
      f = open(filename)                  
      lines = 0
      buf_size = 1024 * 1024
      read_f = f.read # loop optimization
      
      buf = read_f(buf_size)
      while buf:
          lines += buf.count('\n')
          buf = read_f(buf_size)
      
      return linef count_lines_in(filename):
      "Count lines in a file"
      f = open(filename)                  
      lines = 0
      buf_size = 1024 * 1024
      read_f = f.read # loop optimization
      
      buf = read_f(buf_size)
      while buf:
          lines += buf.count('\n')
          buf = read_f(buf_size)
      
      return lines
docs: Count lines in a file