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
New in version 2.5.
The with statement is used to wrap the execution of a block with methods defined by a context manager (see section With Statement Context Managers).
Your IDLE is probably running Python 2.4 or earlier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With