For testing purposes I want to directly execute a function defined inside of another function.
I can get to the code object of the child function, through the code (
Here's a way to return a value from exec'd code:
def exec_and_return(expression): exec(f"""locals()['temp'] = {expression}""") return locals()['temp']
I'd advise you to give an example of the problem you're trying to solve. Because I would only ever use this as a last resort.