Need help with Python scoping rules

Hendrik van Rooyen hendrik at microcorp.co.za
Thu Aug 27 08:38:29 CEST 2009


On Wednesday 26 August 2009 17:14:27 kj wrote:

> As I described at length in another reply, the function in question
> is not intended to be "callable outside the class".  And yes,

I think this might go to nub of your problem - It might help you to think as 
follows: 

A Python class, even after it has been executed, does not really exist except 
as a kind of template or pattern - it is mostly useless until an instance of 
the class is made by calling it with whatever it needs to set up the 
instance.  And once you have an instance, you can do stuff with that 
particular instance.  Before that time, the class is mostly just a promise of 
things to come.

<aside>
The other thing to bear in mind is that you cannot really hide stuff in python 
classes - there are no really private things.
</aside>

> recursive functions in Python *are* restricted in ways that
> non-recursive functions aren't.  The examples I've posted prove
> this point unambiguously.

Yes and no - mostly no -  your examples just illustrate the point I tried to 
make above.

Pythons object model, and its classes, are different from what you are used 
to.  A bare class is mostly useless without an instance, which is ultimately 
why accessing a function in a class from itself like you are doing, without 
reference to an instance, does not work - the function does not exist yet to 
a degree that it can be referenced.  It is kind of subtle, and different from 
other languages.

8<------------- rant against the way things are -----------------------

Welcome to python, and the newsgroup, by the way.

- Hendrik




More information about the Python-list mailing list