File Reading related query

r0g at
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?
> </F>

Hi Usan,

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.


Roger Heathcote

More information about the Python-list mailing list