how to delete "\n"

Thomas Jollans thomas at jollans.com
Mon Jul 12 17:36:11 EDT 2010


On 07/12/2010 11:29 PM, python at bdurham.com wrote:
> Jia,
> 
> print ''.join( open( 'Direct_Irr.txt' ).read().split() )
> 
> Broken out:
> 
> - open(): open file 
> - read(): read its entire contents as one string
> - split(): split the contents into a list of lines
>   (splits lines at \n; does not include \n in split values)

also splits at other whitespace.

> - ''.join(): join list of lines with an empty char
> 
> Malcolm




More information about the Python-list mailing list