I'm an idiot

Peter Hansen peter at engcorp.com
Sat Jun 29 06:23:16 CEST 2002


David Griswold wrote:
> 
> I had no idea it could be this compact.  Thank you for your help!
> 
> David
> 
> Carel Fellinger <carel.fellinger at iae.nl> wrote in
> news:mailman.1025316799.2919.python-list at python.org:
> 
>  and write it like this:
> >
> >    g = open('c:/temp/temp1.txt', 'w')
> >    for line in open('c:/temp/temp.txt'):
> >        g.write(line.strip())

It can't!  At least, it's pretty ugly and not very Pythonic
code (says yet another self-proclaimed expert :-).

Also, it's going to write out all lines in the file as one
big line because it removes the \n at the end of each
but doesn't add any.  

Try some of the other, slightly more verbose, suggestions if
you want your code to be readable.

-Peter



More information about the Python-list mailing list