[Tutor] lists and strings

Pujo Aji ajikoe at gmail.com
Tue Nov 8 20:17:52 CET 2005


yes it is...
 convert list to string:
 L = [1,2,3]
L = [str(x) for x in L]
s = string.join(L,' ')
print len(s)
 convert list to a file
 myF = open(namaFile,"w")
for s in myList[:-1]:
myF.write(str(s)+"\n")
myF.write(str(myList[len(myList)-1]))
myF.close()
  Cheers,
pujo

 On 11/8/05, Mike Haft <m.haft at abdn.ac.uk> wrote:
>
> Hello,
> I've been working on a problem and have now sorted most of it (thanks
> to some help from the list).
>
> All the ways of writing data to a file I know keep telling me that lists
> can't be written to the file. I'm trying to convert data from one set of
> files into files of a different format. But the easiest way to get the
> data from the first set of files is in a list(s).
>
> So, is there any way to convert lists to strings? Or a way to write lists
> to a file?
>
> Thanks
>
> Mike
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051108/b9de233a/attachment.htm


More information about the Tutor mailing list