Need help with Python scoping rules

kj no.email at please.post
Wed Aug 26 09:57:23 EDT 2009


In <jeqdncAMUYvTrwjXnZ2dnUVZ8ludnZ2d at bt.com> "Martin P. Hellwig" <martin.hellwig at dcuktec.org> writes:

>kj wrote:
><cut>
>> First, one of the goals of OO is encapsulation, not only at the
>> level of instances, but also at the level of classes.
>Who says?

Python itself: it already offers a limited form of class encapsulation
(e.g. class variables).  It would be nice if it went all the way
and gave classes their own bona fide scope.  (But I hasten to add:
I *still* don't understand the Python scope model, and not for lack
of trying.  I've only succeeded in finding fragments of this model
explained here and there, like pottery shards: a bit lost in a
tutorial, or some comment in a newsgroup thread, etc.  Maybe the
full, authoritative documentation of Python's scope model got lost
somewhere, and will be found by archaeologists in the 25th century...)

>Anyway, you could be right (I am not capable to judge it) and Python 
>should change on this issue but from what I gathered, Pythons OO is 
>inspired by the following:
>- Don't repeat yourself
>- Containing code into logical units makes it easier to understand and 
>maintain.

...except, apparently, when that code is a recursive function, in
which case one's out of luck.

>> Second, my example shows that Python puts some peculiar restrictions
>> on recursion.  Recursion!  One of the central concepts in the theory
>> of functions!  
><cut>
>It is also one of the best ways to shoot yourself in the foot...

If recursion is so evil, and Python so intent in saving us from
shooting ourselves in the foot, why does it allow recursion at all?

kynn



More information about the Python-list mailing list