class object access in class definition?
ws-news at gmx.at
Wed Mar 7 10:06:22 CET 2001
Depends on what you really need this for
But you can of course access the class object in the __init__ method
>>> class Foo:
... def __init__(self):
... print Foo
Lars Damerow <lars at pixar.com> wrote in message
news:Pine.LNX.4.21.0103061556510.2015-100000 at zero...
> Hi folks!
> Is it possible to reference a class from within its own definition?
> along the lines of:
> class Foo:
> print Foo
> This works for functions--that is,
> >>> def foo():
> ... print foo
> >>> foo()
> <function foo at 0x8111024>
> works as expected, but the class definition above raises a NameError:
> >>> class Foo:
> ... print Foo
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "<stdin>", line 2, in Foo
> NameError: There is no variable named 'Foo'
> Thanks for any pointers!
> lars damerow
> senior unix administrator
> pixar animation studios
> lars at pixar.com
> "Nauseous. Nauseated. The first means 'sickening to contemplate'; the
> means 'sick at the stomach.' Do not, therefore, say, "I feel nauseous,"
> you are sure you have that effect on others."
> - William Strunk Jr., "The Elements of Style"
More information about the Python-list