I am new to the CSV module in Python and was wondering how to create a CSV file dynamically after a function gets called (it can be an empty CSV file)? The CSV file should be either created (if not existing in the directory) or updated in order to add in data (if found existent). Is there a solution that allows me to create a CSV file regardless of the OS used?
Currently, this is what I had thought of so far:
def create():
try:
#What should I do here in order to check whether if the file is existent or not?
except IOError:
#How to create the CSV file here?
finally:
#What should I do here in order to write/append to an existing CSV file?
create()
Can anyone provide a blueprint on how to do this? How can I create a CSV file without manually creating one in my directory?