On 04/03/2015 07:37 AM, Steven D'Aprano wrote:
On Fri, 3 Apr 2015 12:30 pm, Saran A wrote:

#This helper function returns the length of the file
def file_len(f):
     with open(f) as f:
         for i, l in enumerate(f):
             pass
             return i + 1

Not as given it doesn't. It will raise an exception if the file cannot be
opened, and it will return 1 for any file you can read.

After you fix the incorrect indentation, the function is horribly
inefficient. Instead, use this:

import os
os.stat(filename).st_size



No, he actually wants the number of records in the file. So he still needs to read the whole file.

Naturally I figured that out from the phrase in the spec:
   "indicating the total number of records processed"
not from the comment in the code.


--
DaveA
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to