Cloud Stack Ninja

I want to remake the CSV file using outFile.write(str(line)) in an iteration. But this method makes the file like:

OrderedDict([('key1', 'value1'), ('key2', 'value2'), ('key3', 'value3')])OrderedDict([('key1', 'value1'), ('key2', 'value2'), ('key3', 'value3')])OrderedDict(...

adding OrderdedDict at the beginning and with no line breaks. This should be more like:

key1, key2, key3
value1, value2, value3
value1, value2, value3
...

The code I wrote is:

with open(path_to_read_csv_file, "r") as csv_file:
    csv_reader = csv.DictReader(csv_file, delimiter=',')
    for line in csv_reader:
        if [condition]:
            outFile.write(str(line))
        else:
            continue

Any suggestion?



Read more here: https://stackoverflow.com/questions/64403485/ordereddict-and-no-line-breaks-in-the-csv-file

Content Attribution

This content was originally published by ECub Devs at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: