Q: __setattr__/__getattr__

Oleg Orlov orlov at diasoft.ru
Thu Mar 23 08:05:46 EST 2000


I have the __setattr__/__getattr__ code and it works okay.
Now, I want hide some objects attributes and replace
'values' with '__values'. I get infinite recursion and access violation.
The problem is '__values' becomes '_AObject__values' and __setattr__
method cant't find self.__values and call __getattr__ .
How can I resolve the problem?

class AObject:
    def __init__(self, type):
        self.__dict__['type'] = type
        self.__dict__['values'] = [None]*len(type.attributes)

    def __getattr__(self, attr):
        return self.values[self.type.attributes[attr]]

    def __setattr__(self, attr, value):
        if self.__dict__.has_key(attr):
            self.__dict__[attr] = value
            return
        self.values[self.type.attributes[attr]] = value

-----------
Oleg Orlov






More information about the Python-list mailing list