Q: newbie wants to eval()

lynx noone at nowhere.net
Sat Jun 30 16:58:31 EDT 2001


i want to iterate over a list of variable names, comparing each in turn
to a regexp match part, and if the comparison is equal, set the value of
the variable to the value given in another part of the same regexp
match; which seems most obviously done with eval().

i.e., i want to parse a configuration file of the rough form
variable_name = variable_value, and i want to make sure the variable
being set is on a list of variables i'm willing to allow setting, so i
don't want to just eval() the whole line - hence the list iteration.

trouble is, i've never used eval() for anything before, and i can't seem
to get the syntax right. given a loop iterator variable i, which 
iterates over a list of variable names, and a regexp match variable m,
which can be assumed to hold the value i'd like to assign to the named
variable, what should the eval expression look like, and why - how would
the bits and pieces of the complete, correct expression work together? i
ask because none of my current efforts work at all, and i can't figure
out why.

one little additional twist is that the variables i'm trying to set are
globals, defined outside the configuration-file-reading-function itself.
does this change some argument to the eval(), and if so, how?

-- 
   PGP/GnuPG key (ID 1024D/BFE0D6D0) available from keyservers everywhere
    Key fingerprint = 3EBC 97FC 68AA 65F1 65E6  3D36 35F6 4213 BFE0 D6D0
                             "...life goes on
                  long after the thrill of living is gone..."



More information about the Python-list mailing list