Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #88479

Re: New to Programming: Adding custom functions with ipynotify classes

Date 2015-04-03 08:12 -0400
From Dave Angel <davea@davea.name>
Subject Re: New to Programming: Adding custom functions with ipynotify classes
References <3c02ea7e-b562-40c1-99cf-6e9784f37e7b@googlegroups.com> <551e7b7a$0$13012$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.31.1428063173.12925.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

New to Programming: Adding custom functions with ipynotify classes Saran A <ahlusar.ahluwalia@gmail.com> - 2015-04-02 18:30 -0700
  Re: New to Programming: Adding custom functions with ipynotify classes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-03 22:37 +1100
    Re: New to Programming: Adding custom functions with ipynotify classes Dave Angel <davea@davea.name> - 2015-04-03 08:12 -0400
  Re: New to Programming: Adding custom functions with ipynotify classes Denis McMahon <denismfmcmahon@gmail.com> - 2015-04-03 16:39 +0000
    Re: New to Programming: Adding custom functions with ipynotify classes Saran A <ahlusar.ahluwalia@gmail.com> - 2015-04-03 10:56 -0700

csiph-web