Setting "value" of an int-derived class

Ken Schutte kschutte at csail.mit.edu
Sun Sep 3 01:09:31 CEST 2006


Lets say I want an integer class that lets you attach arbitrary 
attributes.  I can simply do:

class foo(int): pass

x = foo(5)
x.text = "okay"
print x, x.text   # prints "5 okay"

So, that's good.  But, how can I change the value of x from 5 to 
something else, without creating a new instance?

I suppose I could create a function that creates a new "foo" and copies 
its attributes, but is there a more direct way?  Is the value "5" stored 
in some special attribute I can just directly modify?

thanks,
Ken



More information about the Python-list mailing list