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


Groups > comp.lang.python > #19276

Re: Looking under Python's hood: Will we find a high performance or clunky engine?

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From 88888 Dihedral <dihedral88888@googlemail.com>
Newsgroups comp.lang.python
Subject Re: Looking under Python's hood: Will we find a high performance or clunky engine?
Date Mon, 23 Jan 2012 10:56:49 -0800 (PST)
Organization http://groups.google.com
Lines 32
Message-ID <862021.904.1327345009173.JavaMail.geo-discussion-forums@preh38> (permalink)
References <3c0bb3d0-6b80-44ec-848a-7296d526c047@t8g2000yqg.googlegroups.com> <mailman.4930.1327255287.27778.python-list@python.org>
Reply-To comp.lang.python@googlegroups.com
NNTP-Posting-Host 112.104.167.201
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace posting.google.com 1327345383 17142 127.0.0.1 (23 Jan 2012 19:03:03 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Mon, 23 Jan 2012 19:03:03 +0000 (UTC)
Cc python-list@python.org
In-Reply-To <mailman.4930.1327255287.27778.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=112.104.167.201; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw
User-Agent G2/1.0
X-Google-Web-Client true
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19276

Show key headers only | View raw


在 2012年1月23日星期一UTC+8上午2时01分11秒,Robert Kern写道:
> 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?
> 
> The .readlines() method is an old API that predates the introduction of 
> iterators to Python. The modern way to do this in one iteration is to use the 
> file object as an iterator:
> 
>    [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 
principle of the iteratee chaining rule in programming.
 
I know manny python programmers just abandon the list comprehension
in non-trivial processes. 

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


Thread

Looking under Python's hood: Will we find a high performance or clunky engine? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-01-22 07:50 -0800
  Re: Looking under Python's hood: Will we find a high performance or clunky engine? Heiko Wundram <modelnine@modelnine.org> - 2012-01-22 18:52 +0100
  Re: Looking under Python's hood: Will we find a high performance or clunky engine? Robert Kern <robert.kern@gmail.com> - 2012-01-22 18:01 +0000
    Re: Looking under Python's hood: Will we find a high performance or clunky engine? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-23 10:56 -0800
    Re: Looking under Python's hood: Will we find a high performance or clunky engine? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-23 10:56 -0800
      Re: Looking under Python's hood: Will we find a high performance or clunky engine? alex23 <wuwei23@gmail.com> - 2012-01-23 22:44 -0800
        Re: Looking under Python's hood: Will we find a high performance or clunky engine? Chris Angelico <rosuav@gmail.com> - 2012-01-24 19:14 +1100
  Re: Looking under Python's hood: Will we find a high performance or clunky engine? Michael Torrie <torriem@gmail.com> - 2012-01-22 17:38 -0700
    Re: Looking under Python's hood: Will we find a high performance or clunky engine? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-01-22 17:04 -0800
      Re: Looking under Python's hood: Will we find a high performance or clunky engine? Michael Torrie <torriem@gmail.com> - 2012-01-22 18:32 -0700
  Re: Looking under Python's hood: Will we find a high performance or clunky engine? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-23 09:11 +0000
  Re: Looking under Python's hood: Will we find a high performance or clunky engine? Grant Edwards <invalid@invalid.invalid> - 2012-01-23 16:08 +0000

csiph-web