Q: newbie wants to eval()

Sean 'Shaleh' Perry shalehperry at home.com
Sat Jun 30 17:40:54 EDT 2001

import string

known_vars = ('foo', 'bar', 'baz')

input = 'foo = 2'

var, data = string.split(input)

if var in known_vars:
        exec(input) # eval takes an expression, assignment is not
        print "unknown variable: %s" % var

for key in globals().keys():
        if key[0] != '_':
                print key

More information about the Python-list mailing list