possible to overide setattr in local scope?

Terry Reedy tjreedy at udel.edu
Tue Jan 22 22:40:43 EST 2008


"glomde" <brkict at gmail.com> wrote in message 
news:9dac9675-992e-4dc5-b085-06f0811939ca at 1g2000hsl.googlegroups.com...
| In a class it is poosible to override setattr, so that you can decide
| how you should
| handle setting of variables.
|
| Is this possible to do outside of an class on module level.
|
| mysetattr(obj, var, value):
|  print "Hello"
|
| So that
|
| test = 5
|
|
| would print
| Hello

An assignment at module level amounts to setting an attribute of an 
instance of the builtin (C coded) module type, which you cannot change. 
Even if you can subclass that type (I don't know), there is no way to get 
the (stock) interpreter to use instances of your module subclass instead. 






More information about the Python-list mailing list