File Reading related query
r0g
aioe.org at technicalbloke.com
Wed Sep 17 13:41:26 EDT 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.
Regards,
Roger Heathcote
http://www.technicalbloke.com
http://movingtoubuntu.technicalbloke.co.uk
More information about the Python-list
mailing list