question on __dict__

Terry Reedy tjreedy at home.com
Thu Nov 22 16:30:46 CET 2001


"Markus Jais" <mjais at web.de> wrote in message
news:pan.2001.11.22.12.52.34.97867.2869 at web.de...
> can somebody tell me, what the difference is between
>
> self.__dict__('foo') = 'bar'
> and
> self.foo = 'bar'

The second translates to the first *UNLESS* there is a .__setattr__()
method.
This is what you should usually use.

Within a __setattr__() method, you *SHOULD* use the first form --
unless you want your program to get caugth in an infinite loop.

(Not sure of impact of 2.2 changes on above statements.)

Terry J. Reedy







More information about the Python-list mailing list