__set_attr__

Jay O'Connor joconnor at cybermesa.com
Thu Jan 25 16:27:33 EST 2001


On Wed, 24 Jan 2001 17:59:19 -0800, "Amritansh Raghav"
<amritansh at mobilian.com> wrote:

>(Newbie alert - its been less than a week)
>
>Under what circumstances does __set_attr__ get callled? I thought it was
>only if the name wasnt found in the dictionary. However I can see my
>function being called even when the name is present. (I print out
>self.__dict__ and also do a self.__dict__.has_key(name) just to make sure
>there isnt a spelling error).
>This is happening within my constructor so I wonder if I need to do
>something special here
>Any help is appreciated
>Thanks


__setattr__ is called for every variable reference.  If you say

	person.lastName = "O'Connor"
it will indeed call __setattr__

__setattr__ is not used for catching erros or misspellings; you simply
use it if there is extra stuff you need to do on variable references.

Take care,
Jay O'Connor
joconnor at cybermesa.com
http://www.cybermesa.com/~joconnor

"God himself plays on the bass strings first, when he tunes the soul"



More information about the Python-list mailing list