string to variable name

Aahz aahz at pythoncraft.com
Thu Apr 24 19:37:19 EDT 2003


In article <b89qi8$2oij$1 at agate.berkeley.edu>,
Benjamin Hartshorne  <ben at hal.rescomp.berkeley.edu> wrote:
>
>I have a function that I want to change the variables in my class:
>
>def myassigner():
>  file = open("mytextfile", 'r')
>  for line in file.readline():
>    m = re.match("^(\w+)\s+(\w+)\s+(\w+)$", line)
>    (newval, var, oldval) = m.groups()
>    inst.var = newval

setattr(inst, 'var', newval)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Why is this newsgroup different from all other newsgroups?




More information about the Python-list mailing list