First let me say I don't think it is a duplicate. I checked Ignore python multiple return value already. This isn't quite what I need.
So, I have a function f:
def f(parameters):
return a,b # returns two values
defined in module1.py
. Now, I want another class to be aware of this function, so I do:
import module1
Class MyClass:
def __init__(self):
self.function = module1.f
This, of course, happens in module2.py
. I need to call it in yet another module,
module3.py
like so:
import module2
instance = module2.MyClass()
otherFunction(args, instance.function )
Here's the catch: the second argument of otherFunction
has to be a function that returns a single value (currently, it returns two). I tried
import module1
Class MyClass:
def __init__(self):
self.function = module1.f[0]
But this does not work. Any ideas? I cannot change module3.py
. I can change the others but then I would have to do a bunch of changes to my project and this seems to be very painful.
I use python 2.6. I would be happy if whatever solution you find would also work for python3, though.