String2List: odd function

Greg Ewing greg.ewing at compaq.com
Wed Jul 28 17:16:11 EDT 1999


Isidor wrote:
> 
> However, I suspect that this use is not among the common uses for
> which exec and eval were designed.

Using eval for something like this is probably overkill.
Eval and exec will accept *any* valid Python expression
or statement, respectively - which can do some nasty
things to the internals of your program if you're not
careful what you feed into them!

This might be quite all right, or it might not,
depending on how bad the consequences will be if
the program blows up due to someone putting in
weird (or even malicious) input.

So there is a use for the other, more laborious
solutions that have been posted. They have the
advantage that they will only accept a certain
subset of Python expressions, and can't cause any
damage if the input doesn't conform to that
subset.

Greg




More information about the Python-list mailing list