Skip to content Skip to sidebar Skip to footer

Writing To CSV From List, Write.row Seems To Stop In A Strange Place

I am attempting to merge a number of CSV files. My Initial function is aimed to: Look Inside a directory and count the number of files within (assume all are .csv) Open the first

Solution 1:

Close the filehandle before the script ends. Closing the filehandle will also flush any strings waiting to be written. If you don't flush and the script ends, some output may never get written.

Using the with open(...) as f syntax is useful because it will close the file for you when Python leaves the with-suite. With with, you'll never omit closing a file again.

with open("./Path/elsewhere/in/file/structure/archive.csv", 'wb') as archive_file:
    wr = csv.writer(archive_file)
    for row in archive:
        wr.writerow(row)
    print row

Post a Comment for "Writing To CSV From List, Write.row Seems To Stop In A Strange Place"