this may seem a little odd, but it would make for a convenient way for me to finish a bit of code.
Because Python methods are objects themselves, could a method have a method of its own? That is, if I wanted to do the following (ignoring syntax):
def methodCaller(someArgs, methodB):
# some stuff here . . .
variableWithAGoodName = methodB()
jonSkeet = methodB.methodC(variableWithAGoodName)
return jonSkeet
Would it be possible? My guess is no, but if methods are just objects, shouldn't it be possible somehow?
Thank you so much!
EDIT: I think as has been posted, I am looking for a high-order function.
My question is somewhat academic as I know I could reorganize my code to do this manner of thing totally differently. But, as it is, I am experimenting with Python to learn at least its basics. I haven't tried this yet, but as I am unfamiliar with Python, it might be possible, just not with this syntax.
Another EDIT: I attempted to be funny with my naming but it made the question unclear. For that I apologize. Here is a better example:
def MethodA(MethodB):
# MethodB is passed as a parameter but is also a method.
# MethodB has a method of its own, somehow, because it is technically still
# an object.
MethodB.MethodC() #Let's pretend it returns nothing here.
# Can this happen?
methodB()were to return objects of different but interface-compatible classes depending on circumstances, your syntax would be fine (with minor modifications). So if B returns aclassDinstance, you end up callingclassD.methodC()in that case, andclassE.methodC()if the returned object was aclassEinstance. This is a fundamental concept of object-oriented programming, so I guess you are getting at something else here, but what?defis only run through when the parent function is called. So you can't call them from outside the parent function, unless you return the nested function as thereturnvalue from the parent function. (see: closures.) This doesn't really do what you want above, though.