Let's say you have this:
class Functions():
def __init__(self):
pass;
def sum(self, x, y):
return x + y;
f = Functions();
print(f[0](1,2));
no, that's not how my code works but it's a example
Basically, I need a way for the last line to print 3, kind of like a way to index Class functions from number. (I would like a Pythonic solution to this if possible)
I've thought of manually setting the "wiring" to do this, but it would be very annoying, as I will be constantly adding new functions.
Is there any magic method for this? I'm pretty sure that __getitem__
is a good resource for this, but I have found myself uncapable of wrapping it's usage around this issue.
Thanks in advance, any help is valuable.