__getattr__ and __setattr__ troubles

Boudewijn Rempt boud at rempt.xs4all.nl
Wed May 24 12:03:22 EDT 2000

Adam Ruth <aruth at intercation.com> wrote:
> Here's your problem:

>>   def setFieldValue(self, field, value):
>>     print "Call: setFieldValue", field, value
>>     if self._tblDef.has_key(field):
>>       self._fields[field]=value
>>     else:
>>       self.__dict__[field]=value

> Since _tblDef doesn't have a "field3", then field3 will be set in
> the __dict__, not in the _fields as you might expect.

No, I _did_ expect field3 to turn up in__dict__ - that's where I
want it since it isn't in the table defintion.

> The __str__ and __coerce__, etc, will all be sent to
> __getattr__ because they are *not* defined in the
> class.  If they were, then __getattr__ would never be
> called.

Ah, that's it.

Boudewijn Rempt  | http://www.valdyas.org

More information about the Python-list mailing list