always raise syntax error!

D

daniel

I'm not quite new to this language, but such error has never happened
so frequently before. I have no idea what to do about it, because
there's actually no syntax error at all !!

I'm using python 2.4.3 on windows, with gvim..
I realize this might because of the tab and space, so I use listchars
in vim to all my tabs and trailing spaces visible, make sure they are
used consistently, but python still raise syntax error, no further
description, and just make no sense to me.

anyone heard of such issue or the like before?
many thanks....

daniel
 
S

Steven D'Aprano

I'm not quite new to this language, but such error has never happened
so frequently before. I have no idea what to do about it, because
there's actually no syntax error at all !!

Looking into my crystal ball, I see that you are correct, there is no
syntax error -- because there is no code! There might not even be a
computer. It is all an illusion brought on by lack of fresh air.

Or maybe not -- my crystal ball is notoriously unreliable.

How about you post the FULL traceback of the error, so we can see for
ourselves if there is a syntax error or not?

e.g.
File "<stdin>", line 1
x{4} = 5
^
SyntaxError: invalid syntax
 
D

daniel

thank you so much for the reply.

I finally re-type all the codes where python would raise syntax error,
then fixed. I did not examine every single word of my old codes though,
there might be some parenthesis not matching somewhere, I guess.

well, I would say, the reason why I could not position the error code
may partly due to the ambiguous message that python provides. the lines
that python pointed to contains no error, I think the error codes must
be too far away from there. anyway, I hope python would make more
detailed error messages, like c++ compilers do. such as: "missing ;" or
"(" not matching...etc.

tks again..

daniel
 
L

Larry Bates

daniel said:
thank you so much for the reply.

I finally re-type all the codes where python would raise syntax error,
then fixed. I did not examine every single word of my old codes though,
there might be some parenthesis not matching somewhere, I guess.

well, I would say, the reason why I could not position the error code
may partly due to the ambiguous message that python provides. the lines
that python pointed to contains no error, I think the error codes must
be too far away from there. anyway, I hope python would make more
detailed error messages, like c++ compilers do. such as: "missing ;" or
"(" not matching...etc.

tks again..

daniel
What Steve is trying to tell you is that you need to copy/paste your
code (with the full traceback) in future messages. We are not mind
readers out here.

Occassionally I will have phantom syntax errors that seem to be
attributable to non-printing characters in a line. Other times the
error is in fact far above the place pointed to by the syntax error.
Start by commenting out large chunks of code with triple quotes and
slowly work towards the lines with a problem.

-Larry Bates
 
C

Cameron Laird

daniel wrote: .
.
. .
.
.
Occassionally I will have phantom syntax errors that seem to be
attributable to non-printing characters in a line. Other times the
error is in fact far above the place pointed to by the syntax error.
Start by commenting out large chunks of code with triple quotes and
slowly work towards the lines with a problem.

-Larry Bates

I'll reinforce part of this: if C++ compilers are our standard,
Python needn't feel shame about its error-reporting. While I've
long advocated upgrades to Python's diagnostic-reporting, it's
simply not true that Python points to "no error". Python reports
a syntax error on a particular line only when there's sufficient
reason.

I recognize a background with C++ will probably necessitate
accomodation to Python, because the two do NOT employ the same
style for syntax questions. Please, though, daniel: don't make
the mistake of thinking Python's syntax is a mystery.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top