reval builtin

Neil Schemenauer nascheme at m67.enme.ucalgary.ca
Fri Apr 16 18:17:32 EDT 1999


On Thu, 15 Apr 1999 01:36:38 GMT, Tim Peters <tim_one at email.msn.com> wrote:
>def reval(string):
>    return eval(string, {"__builtins__": {}})

Yes, I know that trick.  It is much too easy and straight forward
though.  ;)

>If you're determined to allow only literals (I don't see any harm in
>allowing e.g. 1+3), probably easiest to feed the string to the std parser
>module, then crawl over the AST looking for things to complain about.

I thought of doing that but suspected that it would be pretty slow.  I
decided to waste some of my time and hand code a parser.  I will
announce it in another post.  Since your the compiler guy, you should
able to point out all the errors in my code, right?

  picking-tim-bots-umm-brain?-ly y'rs - Neil




More information about the Python-list mailing list