operator overloading + - / * = etc...

Georg Brandl g.brandl-nospam at gmx.net
Sat Oct 7 23:59:09 CEST 2006

Tim Chase wrote:
>>> Can these operators be overloaded?
>> Yes.
> With the caveat of the "=" mentioned in the subject-line (being 
> different from "==")...I haven't found any way to override 
> assignment in the general case.  There might be some oddball way 
> to do it via property() but AFAIK, this only applies to 
> properties of objects, not top-level names/variables.  I'd love 
> to know if there's some workaround for this though...

In almost all cases, binding a name cannot be overridden.

There is a possibility to do that with globals, provided you do

exec code in globals_dict

where globals_dict is an instance of a subclass of dict that has a
customized __setitem__.


More information about the Python-list mailing list