Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed10.multikabel.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python.': 0.04; 'subject:Python': 0.05; 'python': 0.08; 'fred': 0.09; 'reply- to:addr:comp.lang.python': 0.09; 'to:addr:comp.lang.python': 0.09; 'api': 0.09; 'cc:addr:python-list': 0.15; 'code?': 0.16; 'iterates': 0.16; 'non-trivial': 0.16; 'predates': 0.16; 'subject: \n ': 0.16; 'subject:engine': 0.16; 'subject:find': 0.16; 'wrote:': 0.16; 'cc:no real name:2**0': 0.21; 'header:In-Reply- To:1': 0.22; 'cc:2**0': 0.25; 'pm,': 0.26; 'skip:[ 10': 0.27; 'cc:addr:python.org': 0.29; 'lines': 0.30; 'processes.': 0.30; 'subject:?': 0.30; 'correct': 0.31; 'does': 0.32; 'programmers': 0.32; 'list': 0.32; 'header:User-Agent:1': 0.33; 'it?': 0.33; 'object': 0.33; 'from:addr:googlemail.com': 0.34; 'rule': 0.34; 'operating': 0.35; 'received:209.85.160': 0.35; 'file': 0.35; 'passed': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'programming.': 0.38; 'johnson': 0.39; 'received:209': 0.39; 'subject:: ': 0.39; 'more': 0.61; 'presented': 0.62; 'choice.': 0.64; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'reply- to:addr:googlegroups.com': 0.74; '8bit%:61': 0.84; 'abandon': 0.84; 'skip:2 50': 0.91 Newsgroups: comp.lang.python Date: Mon, 23 Jan 2012 10:56:49 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=112.104.167.201; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw References: <3c0bb3d0-6b80-44ec-848a-7296d526c047@t8g2000yqg.googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true MIME-Version: 1.0 Subject: Re: Looking under Python's hood: Will we find a high performance or clunky engine? From: 88888 Dihedral To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: comp.lang.python@googlegroups.com List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1327345018 news.xs4all.nl 6926 [2001:888:2000:d::a6]:45513 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19275 =E5=9C=A8 2012=E5=B9=B41=E6=9C=8823=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=80UTC+= 8=E4=B8=8A=E5=8D=882=E6=97=B601=E5=88=8611=E7=A7=92=EF=BC=8CRobert Kern=E5= =86=99=E9=81=93=EF=BC=9A > On 1/22/12 3:50 PM, Rick Johnson wrote: > > > > What does Python do when presented with this code? > > > > py> [line.strip('\n') for line in f.readlines()] > > > > If Python reads all the file lines first and THEN iterates AGAIN to do > > the strip; we are driving a Fred flintstone mobile. If however Python > > strips each line of the lines passed into readlines in one fell swoop, > > we made the correct choice. > > > > Which is it Pythonistas? Which is it? >=20 > The .readlines() method is an old API that predates the introduction of= =20 > iterators to Python. The modern way to do this in one iteration is to use= the=20 > file object as an iterator: >=20 > [line.strip('\n') for line in f] This is more powerful by turning an object to be iterable. But the list comprehension violates the basic operating=20 principle of the iteratee chaining rule in programming. =20 I know manny python programmers just abandon the list comprehension in non-trivial processes.=20