nested classes

Rainer Deyke root at rainerdeyke.com
Mon Jun 18 22:25:18 EDT 2001


"Mats Wichmann" <xyzmats at laplaza.org> wrote in message
news:3b2e8989.32036776 at news.laplaza.org...
> Java and C++ are compiled.  The class definition is instructions to
> the compiler, and can be self-referential, because the /reference/ is
> not going to happen until the class is loaded - no inconsistency.  Not
> so for Python, the class definition is code that is actually run to
> build the class object, and before that object has been built, there's
> nothing to refer to yet, as Alex said.

That's the way it is now, but it doesn't have to be that way.  Consider
modules.  Circular references between modules work because the module object
is created and added to 'sys.modules' before any code in the module is
executed:

# A.py:
# Module 'A' already exists when the following line executes.
import B

# B.py:
import A


The same principle could be applied to classes, though that isn't
necessarily a good idea.



--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list