working with csv module in python

inshu chauhan insideshoes at gmail.com
Wed Feb 20 05:38:27 EST 2013


On Wed, Feb 20, 2013 at 11:26 AM, Roland Koebler <r.koebler at yahoo.de> wrote:

> 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.
>
>
> Yes I just want to concat the files , not parse/mangle the files.  How can
i simply read all files in a folder in my computer and write them into a
single file ? just by 'printf ' is it possible ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130220/6f757d97/attachment.html>


More information about the Python-list mailing list