working with csv module in python

Peter Otten __peter__ at web.de
Wed Feb 20 05:58:00 EST 2013


inshu chauhan wrote:

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

Assuming the files' last line always ends with a newline and the files use 
the same newline convention:

OUTFILE = "/path/to/outfile.barf"
infiles = glob.glob("/some/folder/*.arff")

with open(OUTFILE, "wb") as outstream:
    for infile in infiles:
        with open(infile, "rb") as instream:
            shutil.copyfileobj(instream, outstream)





More information about the Python-list mailing list