Reputation: 90
I am a beginner learning programming through CS50, currently on week 7 SQL.
I am trying to apply some basic principles on my own machine instead of CS50 IDE on AWS to make sure I can use other environments.
I use visual studio code on windows, and I am currently struggling on some simple lines of code, which are working on the IDE environment but not on my machine. I am simply trying to create a csv file from python, but when I run my code it executes but no csv file is created. Here is my code:
import csv
with open('mycsv.csv', 'w') as f:
writer = csv.writer(f)
writer.writerow(['col1', 'col2', 'col3'])
writer.writerow(['one', 'two', 'three'])
Any ideas ?
Upvotes: 2
Views: 2765
Reputation: 13
If you're working in a virtual environment, the script is creating the file in a different folder, look for the folders above.
Upvotes: 0
Reputation: 629
maybe try w+ instead of w? Like this:
import csv
with open('mycsv.csv', 'w+') as f:
writer = csv.writer(f)
writer.writerow(['col1', 'col2', 'col3'])
writer.writerow(['one', 'two', 'three'])`
w+ forces python to create a new file if that file doesn't exist yet.
Upvotes: 1