I’m new to the csv module (and Python in general). I was running some test code to write a CSV file and I realized that it functions when I run it in the shell but not when I run it from a file in IDLE. When I try the latter, it tells me that “open” is invalid syntax. What’s going on here?
import csv
with open('csvtest.csv', 'w') as f:
writer = csv.writer(f)
writer.writerow('test1', 'test2', 'test3')
Quoth the documentation
Your IDLE is probably running Python 2.4 or earlier.