use str as variable name
cvrebert at gmail.com
Thu Sep 4 09:36:13 CEST 2008
On Thu, Sep 4, 2008 at 12:25 AM, Mathieu Prevot
<mathieu.prevot at gmail.com> wrote:
> I have a program that take a word as argument, and I would like to
> link this word to a class variable.
> class foo():
You should subclass 'object', so that should be:
> width = 10
> height = 20
> a.__argname__= new_value
You're looking for the setattr() built-in function. In this exact case:
setattr(a, arg, new_value)
This is probably covered in the Python tutorial, please read it.
> rather than :
> if arg == 'height':
> a.height = new_value
> elif arg == 'width';
> a.width = new_value
> Can I do this with python ? How ?
Follow the path of the Iguana...
More information about the Python-list