File Reading related query
aioe.org at technicalbloke.com
Wed Sep 17 19:41:26 CEST 2008
Fredrik Lundh wrote:
> Usman Ajmal wrote:
>> Is there any function for reading a file while ignoring *\n* occuring
>> in the file?
> can you be a bit more precise? are we talking about text files or
> binary files? how do you want to treat any newlines that actually
> appear in the file?
I've always just done...
for each in open('filename.txt', 'r'):
each = each.rstrip()
You could wrap this as a generator if you really want it to be a one
liner, personally it's never seemed worth it to me.
More information about the Python-list