dictionaries
Batista, Facundo
FBatista at uniFON.com.ar
Fri Sep 10 17:08:13 EDT 2004
[Steven Bethard]
#- Right idea, wrong type. From the docs at:
#-
#- http://docs.python.org/lib/built-in-funcs.html
#-
#- ] input( [prompt])
#- ]
#- ] Equivalent to eval(raw_input(prompt)).
#-
#- This means that when you use input, it will convert the "1"
#- typed at the
#- prompt to the integer 1. So your code should either be:
#-
#- >>> d = {1:function1, 2:function2}
#- >>> x = input("1 or 2? ")
#- 1 or 2? 1
#- >>> d[x]()
#- function1
#- >>>
Be aware of the serious security issue here!
If the user instead of insert "1", inserts "import os; os.remove(blah)"?
. Facundo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040910/b702a001/attachment.html>
More information about the Python-list
mailing list