+= append class operator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • schwehr@gmail.com

    #1

    += append class operator

    Hi All,

    This is probably a FAQ, but is there an operator mapping for += for
    classes? Or does a += b get converted to a = a + b? 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

    I could always create an append method, but += is nice and concise.

    Thanks,
    -kurt

  • Fredrik Lundh

    #2
    Re: += append class operator

    schwehr@gmail.c om wrote:
    [color=blue]
    > This is probably a FAQ, but is there an operator mapping for += for
    > classes?[/color]

    obj.__iadd__(ot her)
    [color=blue]
    > Or does a += b get converted to a = a + b?[/color]

    only if __iadd__ is not defined.
    [color=blue]
    > 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[/color]

    that's documentation for the operator module.

    special method names are described in the language reference:




    </F>



    Comment

    • schwehr@gmail.com

      #3
      Re: += append class operator

      Awesome. Thanks!

      -kurt

      Comment

      Working...