Executing a function based on user-input
Darrell Gallion
darrell at dorb.com
Tue Jun 6 00:35:53 EDT 2000
From: "Ramachandran Subramanian" <rsubramanian at eudoramail.com>
> I have a number of functions. Based on user input (a number) from a
> menu, I want to execute one of these functions.
> Is there a better way to do this?
>
Don't know if this is better or not.
If security is an issue http://www.python.org/doc/howto/rexec/
>>> glb={'go':go, 'stop':stop}
>>> while 1:
... s=raw_input("-->")
... exec(s, glb)
...
-->go()
go
-->for x in range(5): stop()
stop
stop
stop
stop
-->import os
-->os.listdir('.')
-->print os.listdir('.')
['reSubReturn.py', 't2.py~', 'tabIt.py']
-->
More information about the Python-list
mailing list