On Thu, 25 Jun 2009 18:22:48 +0100, MRAB <pyt...@mrabarnett.plus.com> wrote:
>Angus Rodgers wrote: >> On Thu, 25 Jun 2009 10:31:47 -0500, Kirk Strauser >> <k...@daycos.com> wrote: >> >>> At 2009-06-24T19:53:49Z, Angus Rodgers <twir...@bigfoot.com> writes: >>> >>>> print ''.join(map(detab, f.xreadlines())) >>> An equivalent in modern Pythons: >>> >>>>>> print ''.join(line.expandtabs(3) for line in file('h071.txt')) >> >> I guess the code below would also have worked in 2.1? >> (It does in 2.5.4.) >> >> print ''.join(line.expandtabs(3) for line in \ >> file('h071.txt').xreadlines()) >> >That uses a generator expression, which was introduced in 2.4. Sorry, I forgot that list comprehensions need square brackets. The following code works in 2.1 (I installed version 2.1.3, on a different machine, to check!): f = open('h071.txt') # Can't use file('h071.txt') in 2.1 print ''.join([line.expandtabs(3) for line in f.xreadlines()]) (Of course, in practice I'll stick to doing it the more sensible way that's already been explained to me. I'm ordering a copy of Wesley Chun, /Core Python Programming/ (2nd ed., 2006), to learn about version 2.5.) -- Angus Rodgers -- http://mail.python.org/mailman/listinfo/python-list