Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39335 > unrolled thread
| Started by | Roland Koebler <r.koebler@yahoo.de> |
|---|---|
| First post | 2013-02-20 11:26 +0100 |
| Last post | 2013-02-20 11:26 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: working with csv module in python Roland Koebler <r.koebler@yahoo.de> - 2013-02-20 11:26 +0100
| From | Roland Koebler <r.koebler@yahoo.de> |
|---|---|
| Date | 2013-02-20 11:26 +0100 |
| Subject | Re: working with csv module in python |
| Message-ID | <mailman.2097.1361355963.2939.python-list@python.org> |
Hi, On Wed, Feb 20, 2013 at 10:50:54AM +0100, inshu chauhan wrote: > 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 Do you only want to concat the files, or do you want to parse/mangle them? If you only want to concat the files, I would use some shell-tools, like "cat" on Linux or "copy" on Windows, so copy C:\Users\inshu.chauhan\Desktop\ForModel_600\*.arff C:\Users\inshu.chauhan\Desktop\test2.arff should do it. > Can in some some way I set delimiter to NULL as the prog gives me error if > I do so. Of course -- a CSV without a delimiter doesn't make any sense. > I dont why there is space between the attribute of first column in > reading and there is space between every row too.. Because there's a "split()" missing in your code. You currently tell the CSV-writer to write the columns 2,9,9, , , ,4,4,6, , , ,2 as space-separated CSV. So, try something like rows = [r.split() for r in open(f, "r").readlines()] > Or can I merge these text files without using csv module , directly in > python ? If you don't need to parse/mangle the contents, you don't need the csv module. Simple open the resulting file for writing, and then read out the source files and write their contents into the resulting file. regards Roland
Back to top | Article view | comp.lang.python
csiph-web