* Ian Kelly <ian.g.ke...@gmail.com> [2012-01-22 19:29]: > On Sun, Jan 22, 2012 at 8:50 AM, Rick Johnson > <rantingrickjohn...@gmail.com>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? I cannot understand why it is so important for you to store lines out of a textfile in a list without '\n'. have you ever considered the *pros* of leaving '\n' ? > > > > > Two iterations. And since that is the only possible way to do this, you > are correct, the language is terribly archaic. I suggest you switch to > Ruby ASAP. why there is only one possibility to do so? in a second i found this ''.join(open('test').readlines()).split('\n')
and if you don't like python, then stick to ruby. who cares??? -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at ------------------------------------------------------------------------------- ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 -------------------------------------------------------------------------------
On Sun, Jan 22, 2012 at 8:50 AM, Rick Johnson <rantingrickjohn...@gmail.com> 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?
Two iterations. And since that is the only possible way to do this, you are correct, the language is terribly archaic. I suggest you switch to Ruby ASAP.
-- http://mail.python.org/mailman/listinfo/python-list