Hi all,

I'm playing about with some recursive functions where I am getting 
near the recursion limit. This caused me to do a test, and I am 
puzzled by the different results when run in the prompt, IDLE and 
PythonWin.

My simple test code is:
 >>> c = 0
 >>> def recursion_test():
        global c
        c+=1
        try:
                recursion_test()
        except:
                print c

When this very same code is run in the different interpreters (or, 
different Python environments; I'm not sure of the correct terminology 
here) I get different results. I'll show those, skipping the identical 
code that created them:


Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] 
on win32
 >>> recursion_test()
999
 >>>


IDLE 1.1.1
 >>> recursion_test()
996996


PythonWin 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit 
(Intel)] on win32.              
 >>> recursion_test()
993
  993
  993
 >>>


That the printed numbers differ doesn't worry me; I assume since IDLE 
and PythonWin are implemented in Python, the overhead of running them 
eats up a recursion level or 6, according to how exactly they are 
implemented.

But the two puzzles are:

1) Why the difference in printing format (IDLE prints twice on one 
line, PythonWin thrice with different alignment)?

and,

2) With (and only with) IDLE, I never regain control of the shell 
(note the lack of a terminal '>>>' and have to restart to do anything 
else. That feels bug-like.


It seems a fair bet that the hypothesis for why the printed numbers 
are different is also at play in the last two puzzles. But, I was 
wondering if anyone could say something to shed a bit more light. In 
particular, is my sense of possible bug well grounded?

Thanks and best,

Brian vdB
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to