Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #42263
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <vincent.vandevyvre@swing.be> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'url:launchpad': 0.05; 'subject:file': 0.07; 'f.close()': 0.09; 'python': 0.11; "'r',": 0.16; "'w')": 0.16; 'format:': 0.16; 'from:addr:swing.be': 0.16; 'from:addr:vincent.vandevyvre': 0.16; 'from:name:vincent vande vyvre': 0.16; 'help?': 0.16; 'message-id:@swing.be': 0.16; 'oqapy': 0.16; 'paqager': 0.16; 'received:mobistar.be': 0.16; 'subject:txt': 0.16; 'url:oqapy': 0.16; 'url:paqager': 0.16; 'url:qarte': 0.16; 'v.v.': 0.16; '\xe9crit': 0.16; 'subject:python': 0.16; '>>>': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'txt': 0.31; 'file': 0.32; 'lists': 0.32; 'thanks!': 0.32; 'subject:from': 0.34; "can't": 0.35; 'something': 0.35; 'but': 0.35; 'subject:data': 0.36; 'next': 0.36; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:x 10': 0.40; 'more': 0.64; 'export': 0.74; 'ana': 0.84; 'sta': 0.84 |
| Date | Fri, 29 Mar 2013 19:00:58 +0100 |
| From | Vincent Vande Vyvre <vincent.vandevyvre@swing.be> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Export data from python to a txt file |
| References | <eb74d8be-d3e6-4f65-8a5b-f6a87c1a6af8@googlegroups.com> |
| In-Reply-To | <eb74d8be-d3e6-4f65-8a5b-f6a87c1a6af8@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 8bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3958.1364580518.2939.python-list@python.org> (permalink) |
| Lines | 59 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1364580518 news.xs4all.nl 6849 [2001:888:2000:d::a6]:49993 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:42263 |
Show key headers only | View raw
Le 29/03/13 18:33, Ana Dionísio a écrit :
> 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!
>
>
Something like that:
Python 2.6.5 (r265:79063, Oct 1 2012, 22:07:21)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=[1,3,5,6,10]
>>> b=['a', 't', 'q', 'r', 's']
>>> sta = " ".join([str(i) for i in a])
>>> stb = " ".join(b)
>>> txt = "a " + sta + '\nb ' + stb
>>> f = open('test.txt', 'w')
>>> f.write(txt)
>>> f.close()
>>> f = open('test.txt', 'r')
>>> for line in f:
... print line
...
a 1 3 5 6 10
b a t q r s
>>>
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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