I’ve been trying to create and change a function dynamically in Python. I’ve researched the web and Stack Overflow, but most solutions I see use one of the following, which I don’t want:
exec()
and/orcompile()
lambda
s- closures and nested functions
For example, I have the following code:
def func(a, b, c):
return all([a, b, c])
and I want to change it to:
def func2(a, b, c):
return any([a, b, c])
However, for some reasons I am not allowed to change the code of the function. Is there any way I can do this? I’m looking for a code bytes alternation kind of thing or AST related solution. Any ideas?
New contributor
Luke L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.