#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    __radd__() function


    i have time class and two objects o1 and o2
    with __radd__ funtion to overload +

    def __radd__(self,other):
    self.min+=other.min

    when i call o1+o2, i expect o2.min to get incremented rather than o1 which is not the case
    what i understand is that __radd__ is called when the object is on the right side of the operator, which in this case is o2
    can anyone clear my doubt ?
    thank you
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    114
    Rep Power
    4
    __radd__ will never be called when two objects of the same type are added, and when the objects are different types it is only called when the add method of the object on the left returns NotImplemented. (Ditto the other "reflected" operations.)

IMN logo majestic logo threadwatch logo seochat tools logo