Syntax Error: invalid syntax

676 views
Skip to first unread message

tman

unread,
Oct 22, 2010, 3:52:22 PM10/22/10
to PyScripter
When I Run this script
I get the message Syntax Error: invalid syntax
What is the error? There needs to be a hint!

import csv, sys
filename = "C:/Users/terry/Downloads/tup1012k/tup1012.drf)"
reader = csv.reader(open(filename, "rb"))
try:
for row in reader:
print (row)
except csv.Error, e:
sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))

the error message is pointing to: except csv.Error, e:

any help, please.
thanks
Terry

Andy Milne

unread,
Oct 22, 2010, 4:28:28 PM10/22/10
to pyscr...@googlegroups.com
if the file exists it works fine.

if it does not I get:
C:\>c:\Python26\python.exe foo.py
Traceback (most recent call last):
  File "foo.py", line 3, in <module>
    reader = csv.reader(open(filename, "rb"))
IOError: [Errno 2] No such file or directory: 'C:/Users/terry/Downloads/tup1012k/tup1012.drf)'

When ran in Pyscripter I get the same.

interesting file extension: ".drf)"






--
You received this message because you are subscribed to the Google Groups "PyScripter" group.
To post to this group, send email to pyscr...@googlegroups.com.
To unsubscribe from this group, send email to pyscripter+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyscripter?hl=en.


PyScripter

unread,
Oct 22, 2010, 4:37:43 PM10/22/10
to PyScripter
Are you using Python 3.x?

If yes the syntax for the except statement has changed
except csv.Error as e:

tman

unread,
Oct 22, 2010, 7:05:05 PM10/22/10
to PyScripter
Yes I am running 3.x
and thanks for pointing out the change.
I corrected my script and eliminated the error.
Am much grateful to you and others who pitched in.
thanks, Terry
Reply all
Reply to author
Forward
0 new messages