[Tutor] What's the error?

Magnus Lycka magnus@thinkware.se
Mon Nov 4 13:36:02 2002


At 17:43 2002-11-04 +0000, Alex Gillis wrote:
>Ok, just written a program and I'm now debugging it.  I've got to a point
>where it no longer produces any error messages but still doesn't work.
>Normally i would assume that it has just ignored parts of my programming

Even the laziest python interpreter is bound to do
as instructed. It can't ignore a python program! ;)

>rather than found problems with them (though i can't see why) but when i run
>the script from the editor, the thing freezes and i have to ctrl+alt+delete
>it.  What's going wrong with it?

If you run PythonWin, you can right-click on the snake
icon in the task bar and select "break into running code".
Then you will also see in what line the program was.

It's difficult to say for any of us who haven't seen
the program... It might get stuck in a loop. Maybe
you have a loop where you never exit?

When you say debugging, do you mean that you are
using a debugger? In that case you should be able
to see where you end up. Most python debuggers aren't
very newbie-friendly though.

It's often helpful to put in diagnostic print statements
here and there. Then you should soon be able to see how
far you get, and where you get stuck. Since Python doesn't
have goto, and since recursive calls will exhaust the stack
fairly soon, I would guess it's a loop. Most likely a while
loop where the condition is always true, but it could also
be a for loop that takes much longer than you imagine.

If you have a while loop like this:

while a != b:
     do_stuff()

Change it to:

while a != b:
     print "while a != b =>", a != b
     do_stuff()

I guess you will see and endless stream of something like...

while a != b => 1
while a != b => 1
while a != b => 1
while a != b => 1
while a != b => 1
...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se