Let’s say you have functions a and b. Can you, by calling function a, replace function b with another function?
I know you can do b=a(b), but can you change b with just doing a(b)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Functions and methods are attributes of modules and classes respectively. So you can modify the required attribute to point to another function.
For a class:
And if you have a variable holding the name to replace, then use
setattr, for example:Just replace the string (‘b’) with your variable.
Not sure why you would want to though? It will make for confusing code.