list to string

Sean 'Shaleh' Perry shalehperry at attbi.com
Tue Jul 23 17:40:20 EDT 2002


On 23-Jul-2002 David LeBlanc wrote:
> I have this code:
> 
> fn = file('foo.txt')
> 
> txt = fn.readlines()
> 
> str = ?something?(txt) # or txt.?something?()...
> 
> What's the something? This is probably so obvious, i'm going to feel dumb,
> but I havn't been able to find anything in any doc I've looked at.
> 

perhaps the ugliest syntax in all of python.

''.join(txt) # in other words make a string object from '' and call its join()
             # method

i prefer to use

import string

str = string.join('', txt)




More information about the Python-list mailing list