I'm fairly new to Python and recently started development on a new mac mini. As you know it comes with 2.7 installed.
The problem I'm running across is the Standard Library doesn't seem to be installed.
I get a syntax error when importing modules (SyntaxError: invalid syntax).
I was running this code with the argv datafile.csv
import csv
import sys
stocks.csv = argv
f = open(sys.argv[1], 'rt')
try:
reader = csv.reader(f)
for row in reader:
print row
finally:
f.close()
After awhile of this I decided to run the interpreter and get help.
When I ran the interpreter and do help(csv) or most other modules (sys works just fine) I get this error:
>>> import csv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "csv.py", line 1
import
^
SyntaxError: invalid syntax
Do I need to install the library or am I accessing it wrong?
Thanks.
Do you have a file in the current directory named csv.py with a blank import statement on line 1? Python searches the current directory for imports before it looks at system directories.
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