accessing class variables of private classes
Uwe Mayer
merkosh at hadiko.de
Sun Jan 16 04:35:38 EST 2005
Hi,
I need to access class variables of a class I'd like to make private:
i.e.
class __Bar(object):
pass
class __Foo(__Bar):
def __init__(self):
super(__Foo, self).__init__()
>>> __Foo()
Name Error: global name '_Foo__Foo' is not defined
Here I want to prevent the user of instanciating __Foo from outside of the
module.
i.e.
class __A:
a_list = []
def __init__(self):
__A.a_list.append(self)
>>> __A()
NameError: global name '_A__A' is not defined
Here I want to keep a list of instanciated objects of class __A, so I can
update internal values if they are changed.
Any ideas?
Thanks
Uwe
More information about the Python-list
mailing list