Search code examples
pythonpython-3.xcsvexport-to-csv

Python CSV writer blank line


I have a CSV file, which has

spam

in it. Then, i did

 with open(directory, "a") as config_csv:
    writer = csv.writer(config_csv)
    writer.writerow(["something"])
    writer.writerow(["something else"])

I expected

spam
something
something else

Instead, I got

spam

"something"

"something else"

How do I get the thing I want?


Solution

  • If what you need is just what you said, there's not need for the module csv:

    with open(directory, "a") as config_csv:
        config_csv.write("something\n")
        config_csv.write("something else\n")