getting a reference to a class inside its definition

dan dan at eevolved.com
Mon Jun 18 23:20:52 EDT 2001


Daniel Dittmar wrote:

>> Still, I want to be able to reference a class inside it's own definition.
>> Is this possible or am I going to have to do
> 
> It depends on what you try to achieve. If you want to access class
> variables inside the class definition, do so without any qualification:
> 
> class SomeClass:
>     hello = 'hello'
>     world = 'world'
>     greeting = hello + ', ' + world
> 
> print SomeClass.greeting
> 
> Daniel

Did you know you could also do this:

class SomeClass:
    dict = {}
    dict[1] = "Some value"
    dict["some key"] = 100

print SomeClass.dict
{1: "Some value", "some key": 100}

Dan



More information about the Python-list mailing list