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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.030
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'read.': 0.03; 'naturally': 0.09; 'def': 0.12; '#this': 0.16; 'incorrect': 0.16; 'subject:Adding': 0.16; 'subject:Programming': 0.16; 'exception': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'code.': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'helper': 0.24; 'file.': 0.24; 'this:': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'raise': 0.29; "d'aprano": 0.31; 'steven': 0.31; 'file': 0.32; 'fri,': 0.33; 'comment': 0.34; 'subject:with': 0.35; 'no,': 0.35; 'subject:New': 0.37; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'read': 0.60; 'length': 0.61; 'total': 0.65; 'charset:windows-1252': 0.65; 'received:74.208': 0.68; 'records': 0.73; '2015': 0.84; 'received:74.208.4.194': 0.84
Date Fri, 03 Apr 2015 08:12:38 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version 1.0
To python-list@python.org
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>
In-Reply-To <551e7b7a$0$13012$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V03:K0:Uyq9LyJDvNFUtiNP20meVdfkdmeXTuV+AAivRmB0wN076PFVGZt UolpZjrlvahstKxA5HrTEOpVrVfBjLSacT/u0gjr2VhHKDTuKB1WIqZR5HbAa+SOu/L+oyd H0HFFKXwu8gHm5gEdPv2NnmbAZsw+SqU70J4Mv/n6HAsmJ7lJUD1F5Fast9ZAwvslP4BCj2 CjSWPc4opyXK0dK4pg99Q==
X-UI-Out-Filterresults notjunk:1;
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.31.1428063173.12925.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1428063173 news.xs4all.nl 2909 [2001:888:2000:d::a6]:40710
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:88479

Show key headers only | 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