Re: += append class operator
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: += append class operator

From: Fredrik Lundh <fredrik@pythonware.com>
Date: Wed Apr 19 2006 - 19:24:08 CEST

schwehr@gmail.com wrote:

> This is probably a FAQ, but is there an operator mapping for += for
> classes?

     obj.__iadd__(other)

> Or does a += b get converted to a = a + b?

only if __iadd__ is not defined.

> I would like to make this operator faster for the BitVector class, but
> I don't see += in http://docs.python.org/lib/operator-map.html

that's documentation for the operator module.

special method names are described in the language reference:

    http://docs.python.org/ref/specialnames.html
    http://docs.python.org/ref/numeric-types.html

</F>
Received on Sun Apr 30 23:38:27 2006