best way to increment an IntVar?

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Thu Jun 24 08:27:32 EDT 2010


Dennis Lee Bieber a écrit :
(snip - about Tkinter IntVar type)

> 	It is NOT a numeric "variable" in Python realms.
> 
> 	So var+=increment can't be used because Python would rebind the name
> var to a new object -- but Tkinter would still be hooked to the original
> object and never see the change.

 >>> foo = []
 >>> bar = foo
 >>> foo += [1]
 >>> foo
[1]
 >>> bar
[1]
 >>> bar is foo
True
 >>> foo.__iadd__([2])
[1, 2]
 >>> _ is foo
True
 >>>

IOW : __iadd__ doesn't necessarily returns a new object !-)






More information about the Python-list mailing list