I have a class with the following structure:
class Example:
def __init__(self, value, foo):
self.value = value
self.foo = foo
self.bar = self.modify_stuff(value, foo)
def modify_stuff(self, value, foo):
""" some code """
pass
I want to create an instance of the class, and then be able to refer to value directly, like this:
ex = Example(3, 'foo')
ans = 5 + ex
Instead of:
ans = 5 + ex.value
How can I do this?
__add__/__radd__/etc to have the appropriate behaviorpandas.DataFrame? if I create something likedf = pd.DataFrame([1, 2, 3, 4])I can access the data directly fromdf(likedf + 5), I don't need to do something likedf.data + 5__add__/__radd__/etc to have the appropriate behavior.