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


Groups > comp.lang.python > #39330

working with csv module in python

Date 2013-02-20 10:50 +0100
Subject working with csv module in python
From inshu chauhan <insideshoes@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2093.1361353864.2939.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

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 !!!

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


Thread

working with csv module in python inshu chauhan <insideshoes@gmail.com> - 2013-02-20 10:50 +0100

csiph-web