Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42261

Re: Export data from python to a txt file

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Export data from python to a txt file
Date 2013-03-29 17:58 +0000
References <eb74d8be-d3e6-4f65-8a5b-f6a87c1a6af8@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3956.1364579857.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 29/03/2013 17:33, Ana Dionísio 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")

You'll have to write your data here.

>   f.write("\n")

And here.

>   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]))

You rarely need a loop like this in Python.
for x in a:
   doSomething
is the usual way of writing this.  But you don't need this anyway.  Just 
use the string join method as you can't use csv, which tells me it's 
homework, so I'll leave you to it :)

>
>   f.close()"
>
> But it doesn't have the format I want. Can you help?
>
> Thanks!
>

-- 
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.

Mark Lawrence

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Export data from python to a txt file Ana Dionísio <anadionisio257@gmail.com> - 2013-03-29 10:33 -0700
  Re: Export data from python to a txt file Jason Swails <jason.swails@gmail.com> - 2013-03-29 13:52 -0400
  Re: Export data from python to a txt file rusi <rustompmody@gmail.com> - 2013-03-29 10:55 -0700
  Re: Export data from python to a txt file Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-03-29 17:58 +0000
  Re: Export data from python to a txt file Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-03-29 19:00 +0100
  Re: Export data from python to a txt file Peter Otten <__peter__@web.de> - 2013-03-29 19:11 +0100

csiph-web