Export data from python to a txt file
rusi
rustompmody at gmail.com
Fri Mar 29 13:55:59 EDT 2013
On Mar 29, 10:33 pm, Ana DionĂsio <anadionisio... at gmail.com> wrote:
> Hello!!!
>
> I have this lists a=[1,3,5,6,10], b=[a,t,q,r,s] and I need to export it to a txt file and I can't use csv.
>
> And I want the next format:
>
> a 1 3 5 6 10
> b a t q r s
>
> I already have this code:
>
> "f = open("test.txt", 'w')
> f.write("a")
> f.write("\n")
> f.write("b")
> f.write("\n")
>
> for i in xrange(len(a)):
> LDFile.write("\t")
> LDFile.write(str(a[i]))
> LDFile.write("\t")
> LDFile.write(str(b[i]))
>
> f.close()"
>
> But it doesn't have the format I want. Can you help?
>
> Thanks!
Dunno about LDFile. [Neither does google]
You can try:
>>> a=[1,3,7,10,100]
>>> "a " + " ".join(map(str,a))
'a 1 3 7 10 100'
More information about the Python-list
mailing list