use str as variable name

Mathieu Prevot mathieu.prevot at gmail.com
Thu Sep 4 09:25:37 CEST 2008


Hi,

I have a program that take a word as argument, and I would like to
link this word to a class variable.

eg.
class foo():
  width = 10
  height = 20

a=foo()
arg='height'
a.__argname__= new_value

rather than :

if arg == 'height':
  a.height = new_value
elif arg == 'width';
  a.width = new_value

Can I do this with python ? How ?

Thanks,
Mathieu



More information about the Python-list mailing list