Problem with the "for" loop syntax

Cameron Simpson cs at zip.com.au
Wed Jun 19 23:11:13 EDT 2013


On 20Jun2013 11:09, Chris Angelico <rosuav at gmail.com> wrote:
| On Thu, Jun 20, 2013 at 11:02 AM, Arturo B <a7xrturodev at gmail.com> wrote:
| > Fixed, the problem was in
| > HANGMANPICS
| >
| > I didn't open the brackets.
| > Thank you guys :)
| 
| General debugging tip: Syntax errors are sometimes discovered quite
| some way below the actual cause. The easiest way to figure out what's
| the real cause is to start cutting away unnecessary code until all
| that's left is the tiniest part that still has the error. This is also
| very helpful as a prerequisite to posting on a list like this, so even
| if you can't find the problem yourself by this method (you often will,
| though), it's well worth doing.

Also, opening-and-not-closing a set of brackets is almost the only
way in Python to make this kind of error (syntax at one line, actual
mistake far before).

See if your editor has a show-the-matching-bracket mode.

I use vi/vim and it both shows the matching bracket when the cursor
is on one and also have a keystroke to bounce the curser between
this bracket and the matching one.

If you suspect you failed to close a bracket, one approach is to
go _below_ the syntax error (or right on it) and type a closing
bracket. Then see where the editor thinks the opening one is.

If you have a syntax highlighting editor (highlights keywords,
colours quoted text differently, etc) it can also be useful for
finding errors; the text will be the wrong colour at some point.

Just a few suggestions to aid finding this kind of thing without
outside help.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

Are you experiencing more Windows95 crashes than the norm? How on earth
would you _know_?       - John Brook <johnb at research.canon.com.au>
                          reporting about a new virus



More information about the Python-list mailing list