0

I'm looking to create a new .csv file using python and then write to the file after that. I couldn't find a command to create a new file using the CSV library. I thought something like

NewFile = csv.creatfile(PATH)

might exist but I couldn't find something like that.

Thank you in advance! Happy to answer any questions you may have!

7
  • 1
    What don't you understand about the example in the documentation? Commented Feb 15, 2016 at 19:54
  • You have read the documentation, right? Commented Feb 15, 2016 at 21:24
  • @martineau Yes I have! Commented Feb 15, 2016 at 23:51
  • @Evert I do understand the example. Writing to a file is not my issue, creating a new file is. Commented Feb 15, 2016 at 23:52
  • Which is exactly what open('eggs.csv', 'wb') in the example does. File creation is also in the tutorial. Commented Feb 16, 2016 at 0:51

1 Answer 1

3

The csv module doesn't handle file creation; Python handles file creation as a builtin function called open -- once you have a file handle created using open, you can use it with csv.writer or csv.DictWriterto write data to the file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.