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

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'from:addr:yahoo.co.uk': 0.04; 'anyway.': 0.05; 'subject:file': 0.07; 'string': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; "'w')": 0.16; 'csv,': 0.16; 'format:': 0.16; 'help?': 0.16; 'rarely': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:txt': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'tells': 0.24; 'url:moin': 0.24; 'code:': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'leave': 0.29; "doesn't": 0.30; 'url:wiki': 0.31; 'txt': 0.31; 'file': 0.32; 'lists': 0.32; 'this.': 0.32; 'thanks!': 0.32; 'url:python': 0.33; 'subject:from': 0.34; "can't": 0.35; 'usual': 0.35; 'but': 0.35; 'subject:data': 0.36; 'next': 0.36; 'method': 0.36; "i'll": 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:x 10': 0.40; 'read': 0.60; "you're": 0.61; "you'll": 0.62; 'charset:windows-1252': 0.65; 'export': 0.74; 'ana': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Export data from python to a txt file
Date Fri, 29 Mar 2013 17:58:34 +0000
References <eb74d8be-d3e6-4f65-8a5b-f6a87c1a6af8@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host host-92-18-20-125.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130307 Thunderbird/17.0.4
In-Reply-To <eb74d8be-d3e6-4f65-8a5b-f6a87c1a6af8@googlegroups.com>
X-Antivirus avast! (VPS 130329-0, 29/03/2013), Outbound message
X-Antivirus-Status Clean
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.3956.1364579857.2939.python-list@python.org> (permalink)
Lines 51
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1364579857 news.xs4all.nl 6891 [2001:888:2000:d::a6]:42367
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:42261

Show key headers only | 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