Dec-04-2018, 02:20 PM
(This post was last modified: Dec-04-2018, 02:20 PM by Gribouillis.)
What you want is not possible because one cannot overload or override the assignment operator in python. The semantics of
You could have either another attribute assignment or a function call to mean set self.data to value 2 because attribute assignment can be overriden
ref = 2is to update the locals dictionary (or the globals dictionary) to have the key 'ref' point to the value
2
. Note that the meaning of the statement is purely symbolic. The word 'ref' is used but not any operation that you have done before with it. That's why Python's documentation often uses 'name' instead of 'variable'. A variable in python is nothing but a word.You could have either another attribute assignment or a function call to mean set self.data to value 2 because attribute assignment can be overriden
r.f = 2 ref(2)However this will slow down the execution because direct attribute access is fast.