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


Groups > comp.lang.python > #29376

Re: Python garbage collector/memory manager behaving strangely

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'subject:Python': 0.05; 'lines,': 0.05; 'pop': 0.05; 'line:': 0.07; 'method,': 0.07; 'raises': 0.07; 'referring': 0.07; 'appropriate.': 0.09; 'beginners': 0.09; 'exception,': 0.09; 'nameerror:': 0.09; 'namespace': 0.09; 'runtime': 0.09; 'sep': 0.09; 'whichever': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'ignore': 0.13; 'len(line)': 0.16; 'programmer,': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'else,': 0.17; 'yield': 0.17; 'saying': 0.18; '>>>': 0.18; 'code,': 0.18; 'changes': 0.20; '"",': 0.22; 'defined': 0.22; "i'd": 0.22; 'cc:2**0': 0.23; 'ignored.': 0.23; 'statement': 0.23; "i've": 0.23; 'cc:no real name:2**0': 0.24; 'least': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(most': 0.27; 'am,': 0.27; 'done.': 0.27; 'replace': 0.27; 'to?': 0.27; "doesn't": 0.28; 'lines': 0.28; 'subject:/': 0.28; "d'aprano": 0.29; 'restricted': 0.29; 'steven': 0.29; "skip:' 10": 0.30; 'usually': 0.30; 'function': 0.30; 'code': 0.31; 'file': 0.32; 'traceback': 0.33; 'clear': 0.35; 'built-in': 0.35; 'pm,': 0.35; 'something': 0.35; 'there': 0.35; 'add': 0.36; 'but': 0.36; 'should': 0.36; 'subject:: ': 0.38; 'comment': 0.38; 'skip:l 20': 0.38; 'things': 0.38; 'received:192': 0.39; 'received:192.168': 0.40; 'end': 0.40; 'kind': 0.61; 'different': 0.63; 'more': 0.63; 'header:Reply- To:1': 0.68; 'lives': 0.71; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'confusion.': 0.84; 'fortunately,': 0.84; 'moderately': 0.84; 'received:74.208.4.194': 0.84; 'sometimes.': 0.84; 'mistake': 0.91; 'shadow': 0.91; 'angel': 0.93
Date Mon, 17 Sep 2012 08:03:47 -0400
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0
MIME-Version 1.0
To Steven D'Aprano <steve+comp.lang.python@pearwood.info>
Subject Re: Python garbage collector/memory manager behaving strangely
References <CEE8C35195DB944D9C75ABB15A04193B14E77085@EHKG17P32001A.csfb.cs-group.com> <5056871E.7050206@davea.name> <mailman.818.1347849124.27098.python-list@python.org> <59f8c664-8f11-439e-8002-ca76ee24a632@g7g2000pbh.googlegroups.com> <mailman.830.1347878839.27098.python-list@python.org> <50570de3$0$29981$c3e8da3$5496439d@news.astraweb.com>
In-Reply-To <50570de3$0$29981$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:Gjw2645Ajg+S+CXNY8p1hX6Qli2FZeii2ymKYClpLG2 jjKma24DPWkjMc5hZzLjCDL9tYlGTo6sWtRJTeh9M+th8jPgNy jkMQjYsxK/j/1wHTSP4C4qM/Sj2YCfM8Iv8VCUhv4I4bMPFCXa zr35WU8JnHRWtS8HT5nFcoVlbwucOhaOrdj7Lv5AHOLJH/vIhM VAOqwbPCgANrGnOkG0mqtThUq2K9pAf8jd8wOrbeLpJLbCPf+z 7QHVoU+8K+MZcs2LoltIXzk6V4TdZCG7zncymBVuxvobvnfec0 /Y+LoRzGR4aCqxG9xA5yAVMJ+dHU2wfr/5dZwxMs3K4IwuX5A= =
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.832.1347883451.27098.python-list@python.org> (permalink)
Lines 53
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1347883451 news.xs4all.nl 6846 [2001:888:2000:d::a6]:35435
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:29376

Show key headers only | View raw


On 09/17/2012 07:47 AM, Steven D'Aprano wrote:
> On Mon, 17 Sep 2012 06:46:55 -0400, Dave Angel wrote:
>
>> On 09/16/2012 11:25 PM, alex23 wrote:
>>>     def readlines(f):
>>>         lines = []
>>>         while "f is not empty":
>>>             line = f.readline()
>>>             if not line: break
>>>             if len(line) > 2 and line[-2:] == '|\n':
>>>                 lines.append(line)
>>>                 yield ''.join(lines)
>>>                 lines = []
>>>             else:
>>>                 lines.append(line)
>> There's a few changes I'd make:
>> I'd change the name to something else, so as not to shadow the built-in,
> Which built-in are you referring to? There is no readlines built-in.
>
> py> readlines
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> NameError: name 'readlines' is not defined
>
>
> There is a file.readlines method, but that lives in a different namespace 
> to the function readlines so there should be no confusion. At least not 
> for a moderately experienced programmer, beginners can be confused by the 
> littlest things sometimes.

You're right of course, and that's not restricted to beginners.  I've
been at this for over 40 years, and I make that kind of mistake once in
a while.  Fortunately, when I make such a mistake on this forum, you
usually pop in to keep me honest.  When I make it in code, I either get
a runtime error, or no harm is done.

>
>> and to make it clear in caller's code that it's not the built-in one.
>> I'd replace that compound if statement with
>>       if line.endswith("|\n":
>> I'd add a comment saying that partial lines at the end of file are
>> ignored.
> Or fix the generator so that it doesn't ignore partial lines, or raises 
> an exception, whichever is more appropriate.
>
>
>


-- 

DaveA

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


Thread

RE: Python garbage collector/memory manager behaving strangely "Jadhav, Alok" <alok.jadhav@credit-suisse.com> - 2012-09-17 10:28 +0800
  Re: Python garbage collector/memory manager behaving strangely alex23 <wuwei23@gmail.com> - 2012-09-16 20:25 -0700
    Re: Python garbage collector/memory manager behaving strangely 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-16 21:39 -0700
    Re: Python garbage collector/memory manager behaving strangely Dave Angel <d@davea.name> - 2012-09-17 06:46 -0400
      Re: Python garbage collector/memory manager behaving strangely Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-17 11:47 +0000
        Re: Python garbage collector/memory manager behaving strangely Dave Angel <d@davea.name> - 2012-09-17 08:03 -0400
        Re: Python garbage collector/memory manager behaving strangely aahz@pythoncraft.com (Aahz) - 2012-11-14 06:19 -0800
          Re: Python garbage collector/memory manager behaving strangely Dieter Maurer <dieter@handshake.de> - 2012-11-15 08:31 +0100
    RE: Python garbage collector/memory manager behaving strangely "Jadhav, Alok" <alok.jadhav@credit-suisse.com> - 2012-09-17 19:00 +0800
  Re: Python garbage collector/memory manager behaving strangely Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-11-15 12:20 +0100

csiph-web