I have a Python program that accepts user input. I store user input of a string variable called userInput. I want to be able to call a string entered by a user ...
userInput = input("Enter a command: ")
userInput()
From this I get the error: TypeError: object 'str' cannot be called
I currently have a program that does something like this:
userInput = input("Enter a command: ")
if userInput == 'example_command':
example_command()
def example_command():
print('Hello World!')
Obviously, this is not a very efficient way to handle many commands. I want to make str obj callable - anyway to make it?
source
share