Q: newbie wants to eval()

Sean 'Shaleh' Perry shalehperry at home.com
Sat Jun 30 23:40:54 CEST 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
else:
        print "unknown variable: %s" % var

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






More information about the Python-list mailing list