0

I have requirement in Python that, When I do this kind of code

class B(): pass
A = B # not really assign value, but to invoke a function to do some work.

I want to invoke other function when do assignment "A = B", so I think about operator overloading, I found a link for this:

http://thepythonguru.com/python-operator-overloading/

But it seems we cannot overload the operator "=", is there any workaround for this?

fang ming
  • 57
  • 1
  • 6
  • 2
    Don't do this, using operators to produce side effects doesn't sound like an awesome idea to me. – cs95 Mar 15 '18 at 05:19
  • 1
    The language exposes no way to do this directly. You would have to hack together something. It sounds highly inadvisable. – juanpa.arrivillaga Mar 15 '18 at 05:23
  • 2
    You cannot: assignment is not "an operator" in Python. Assignment is a kind of _statement_ instead. You can no more change what an assignment statement does than, e.g., you can change what a `return` statement does. – Tim Peters Mar 15 '18 at 05:24

0 Answers0