[Tutor] how to join two text files ?
Albert-Jan Roskam
fomcl at yahoo.com
Sun Mar 27 15:41:33 CEST 2011
Hello,
If the files are not too big, you could do something like:
with open("/home/me/Desktop/test.csv", "wb") as w:
writer = csv.writer(w)
for f in glob.glob("/home/me/Desktop/files/*.txt"):
rows = open(f, "rb").readlines()
writer.writerows(rows)
Cheers!!
Albert-Jan
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public
order, irrigation, roads, a fresh water system, and public health, what have the
Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
________________________________
From: Mateusz K <km_wawa at vp.pl>
To: tutor at python.org
Sent: Sat, March 26, 2011 10:08:43 PM
Subject: [Tutor] how to join two text files ?
Hello,
I have many text files, where data is delimited by space.
Each file contain three colums: coordinate x, coordinate y and value for this
location.
I would like to join this data to get one big file which will contain
columns:
coordinate x, coordinate y, value1,value2,..., value_n and save it to another
text file.
I wrote script, but there's some stupid error (like "\n" character although
I have added .rstrip() command).
Coul You tell me what is most convenient way to join this data
(maybe by using csv module?)?
=========
Best regards,
Mateusz
_______________________________________________
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110327/d8f907e8/attachment.html>
More information about the Tutor
mailing list