Finding "hidden" syntax errors

Eru ripolles at LALALAaditel.org
Sun Jun 13 20:05:28 EDT 2004


eltronic at juno.com escribio:
> 
> On Fri, 11 Jun 2004 13:03:38 -0500 "Larry Bates writes:
>> 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.  
> 
> [ some advice about error checking -- snipped ]

Another problem that arises from time to time which produces the effect
described by the OP is an "unclosed parens", that is, a parens that was
open and never closed (or a square bracket).

As Python considers an unclosed parens as an implicit continuation of
the statement in the following line, the error is often "detected" in
some place PAST the actual error.

Something similar happens with "unclosed strings", but any editor with a
decent syntax highlighting makes you notice this almost instantly.

My advice is to explore your editor and learn if there is some way to
get "help" with your parents. Emacs does this veri well AFAIK, and in
Vim you can 

:set showmatch

to get Vim show you some highlights about parens; you can also press %
when you are on a parens to move to the corresponding (opening/closing)
one.

My .02 :)

-- 
Daniel Ripolles ( Eru )
Make Source, Not War
for(0..pop){for($c=$_%2;$_>>=1;){$c=$_%2 .$c}print"$c\n"}




More information about the Python-list mailing list