working with csv module in python

inshu chauhan insideshoes at gmail.com
Wed Feb 20 04:50:54 EST 2013


I have 10 simple text files with 3 columns x,y,z delimited by "space". I am
trying to combine these 10 files to get a single text file.

Eg. of data in 10 files is
299 446 2


I had written this prog for merging files:


import csv
import glob

with open(r"C:\Users\inshu.chauhan\Desktop\test2.arff", "w") as w:
    writer = csv.writer(w, delimiter = ' ', quotechar = ' ' ,quoting =
csv.QUOTE_MINIMAL)
    for f in glob.glob(r"C:\Users\inshu.chauhan\Desktop\For
Model_600\*.arff"):
        rows = open(f, "r").readlines()
        writer.writerows(rows)



But the result after merging the files is not I need , it is something like
:
2 9 9      4 4 6      2


2 9 9      4 4 7      2


2 9 9      4 4 8      2


2 9 8      4 4 9      2


Can in some some way I set delimiter to NULL as the prog gives me error if
I do so. I dont why there is space between the attribute of first column in
reading and there is space between every row too..

Or can I merge these text files without using csv module , directly in
python ?

Looking forward to your suggestions.

Thanks in advance !!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130220/26879a08/attachment.html>


More information about the Python-list mailing list