MasterHolbytla MasterHolbytla - 4 months ago 15
Python Question

Call a Python function with arguments based on user input

I would like to call a function from a user input, but include arguments in the parenthesis. For example, if I have a function that takes one argument:

def var(value):

I would like to ask the user for a command and arguments, then call the function with the arguments:

Input Command: var("Test")


Assuming you absolutely trust the input, just use eval

eval(str(input("Command: ")))

"str" is important for some variable types.