I am using Flask. I want to call a function using globals.
I make an API call using parameters passed as a dictionary:
my_parameters = {
"function" : "add_numbers",
"number_1" : 100,
"number_2" : 200
}
I can call the function in Flask as follows:
@app.route("/call_my_function/", methods=["GET"])
def call_my_function():
res = globals()[request.args.get('function')](100, 200)
return(res)
...which works fine, but as you can see I am harcoding the 100 and 200 arguments. I want these arguments to be passed from the my_parameters
dictionary. I tried this:
@app.route("/call_my_function/", methods=["GET"])
def call_my_function():
res = globals()[request.args.get('function')](list(args.values())[1:])
return(res)
But the arguments are not accepted in globals. It says:
TypeError: add_numbers() missing 1 required positional argument