Finding "hidden" syntax errors

L

Larry Bates

It doesn't happen often, but once in a while I will
introduce a syntax error into a Python program I'm
working on (in IDLE) and doing File-Check responds
with the expected "Failed to check, syntax error -
invalid syntax". The problem is where the cursor
stops is perfectly legal syntax. I then begin
going through the laborious job of cutting out
pieces of the code until I find what is wrong. Is
there some easier way of doing this. I tried
pychecker but got nowhere because it said it
couldn't import (which I'm sure is because of the
syntax error). Does anyone out there have a "better"
way of tracking down these difficult to locate
errors?

Thanks in advance for any hints.

Regards,
Larry Bates
Syscon, Inc.
 
M

Miki Tebeka

Hello Larry,
I tried pychecker but got nowhere because it said it couldn't import
(which I'm sure is because of the syntax error). Does anyone out there
have a "better" way of tracking down these difficult to locate errors?
I'm using pychecker. It says where the error is:
--- syn.py ---
def f(x):
if x = 2: # Syntax error
print "YO"
else:
print "Halt! Who goes there?"
--- syn.py ---

[10:45] $pychecker syn.py
Processing syn...
SyntaxError: invalid syntax (syn.py, line 2)
if x = 2: # Syntax error
^

Warnings...

syn:1: NOT PROCESSED UNABLE TO IMPORT
[10:45] $

pychecker found out that the problem is in line 2.

Maybe some concrete example?

Bye.
 

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,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top