def inventory(): print "1" def close(): print "2" global_commands = { 'inventory': inventory(), 'close': close() } def test_command(): response = raw_input() if response in global_commands().keys and callable(global_commands()['response']): global_commands()['response']() else: print "Command not found" ''' def test_command(): a = raw_input("Fill in function name:") if a in global_commands().keys() and callable(global_commands()['a']): global_commands()['a']() else: print 'Function not found' # http://stackoverflow.com/questions/5134482/python-call-function-from-user-input ''' test_command()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question