getting a reference to a class inside its definition
Alex Martelli
aleaxit at yahoo.com
Mon Jun 18 11:45:49 EDT 2001
"dan" <dan at eevolved.com> wrote in message
news:9noX6.14930$uR5.1138042 at news20.bellglobal.com...
...
> Still, I want to be able to reference a class inside it's own definition.
The class object does not *EXIST* until its classbody has
*FINISHED* executing, I believe. That makes it rather hard
to reference it. You can reference the *dictionary* that
will become the namespace for the class's object -- it's
what locals() returns in class-body scope.
> Is this possible or am I going to have to do
>
> class SomeClass:
> pass
> SomeClass.clsref = SomeClass
>
> because that's what I'm doing now...
I think this is the correct way (well it DOES create a
reference-cycle of course, which may well make for some
garbage-collection work, but I guess you know that).
Alex
More information about the Python-list
mailing list