How about this:
def test():
exec (code, globals())
f()
More Related Contents:
- Call a function from another file?
- How do I call a function from another .py file?
- Setting variables with exec inside a function
- How do I get the return value when using Python exec on the code object of a function?
- How function is getting called without defining in python [closed]
- Check if input is empty
- Why does my recursive function return None?
- How do I execute a string containing Python code in Python?
- Behavior of exec function in Python 2 and Python 3
- Determine function name from within that function (without using traceback)
- Importing from builtin library when module with same name exists
- Can’t import my own modules in Python
- How to plot multiple functions on the same figure, in Matplotlib?
- How to get local variables updated, when using the `exec` call?
- Best way to check function arguments? [closed]
- How are Python in-place operator functions different than the standard operator functions?
- How do Python functions handle the types of parameters that you pass in?
- How do I define a function with optional arguments?
- Is it possible to run function in a subprocess without threading or writing a separate file/script.
- What could cause a python module to be imported twice?
- Namespaces with Module Imports
- from … import OR import … as for modules
- What is first class function in Python
- In Python, when should I use a function instead of a method?
- Python, doing conditional imports the right way
- Python Turtle.Terminator even after using exitonclick()
- Tkinter PIL image not displaying inside of a function
- Returning multiple values from pandas apply on a DataFrame
- Use a string to call function in Python [duplicate]
- Are functions objects in Python?