Access from class variable to one on constructor [Solved]

Kless jonas.esp at googlemail.com
Mon Feb 23 05:48:19 EST 2009


Thanks Gabriel. You have reason, and I was having a design error.

On 23 feb, 10:02, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> En Mon, 23 Feb 2009 07:40:47 -0200, Kless <jonas.... at googlemail.com>  
> escribió:
>
> > How to access from a class variable to one that is initialized on the
> > constructor?
> > --------------
> > class Foo():
> >   foo = bar  # I want to access *from here* to variables created on
> > the constructor.
>
> >   def __init__(self, bar_init):
> >     self.bar = bar_init
> > --------------
>
> Unless I misunderstand you, you can't do that. Class variables are shared  
> by all instances and don't depend on a particular instance - they exist  
> even *before* any instance is created.
>
> > Note: I've to create a subclass where the parent class to get
> > variables using *for i in dir(self): * so it doesn't get variables
> > initialized on the constructor.
>
> This part I don't understand at all. Perhaps a concrete example, showing  
> what you actually want at the end?
>
> --
> Gabriel Genellina




More information about the Python-list mailing list