iain duncan <[EMAIL PROTECTED]> writes:
> I know one has to be *very careful* using eval with anything that comes
> from a url submission. It would however, but out a lot of conditionals.
> Can anyone tell me if it is safe to eval a string provided I previously
> do a positive match against it with an re containing alphabetical
> characters only? Is there anyway for python to do damage evaling one
> word?
Why don't you use a dictionary?
Something like:
actions = {
'choice1':function1,
'choice2':function2,
}
actions[text]()
Example:
>>> def a():
... print "a"
...
>>> def b():
... print "b"
...
>>> actions = {
... 'a':a,
... 'b':b,
... }
>>> actions['a']()
a
>>> actions['b']()
b
>>> def c():
... print "Hi mom!"
...
>>> actions['c'] = c
>>> actions['c']()
Hi mom!
>>>
--
Jorge Godoy <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---