At 2009-06-24T19:53:49Z, Angus Rodgers <[email protected]> writes:
> stop = 3 # Tab stops every 3 characters
> from types import StringType # Is this awkwardness necessary?
> detab = lambda s : StringType.expandtabs(s, stop) # Or use def
> f = open('h071.txt') # Do some stuff to f, perhaps, and then:
> f.seek(0)
> print ''.join(map(detab, f.xreadlines()))
> f.close()
An equivalent in modern Pythons:
>>> print ''.join(line.expandtabs(3) for line in file('h071.txt'))
In short: expandtabs is a method on strings, there's no need to seek to the
beginning, and files are closed when they are garbage collected (although I
can't make myself not close output files after years of doing so), and map()
is largely deprecated in favor of list comprehensions and generator
functions.
--
Kirk Strauser
The Day Companies
--
http://mail.python.org/mailman/listinfo/python-list