2008/9/4 Chris Rebert <cvrebert@gmail .com>:
Indeed.
I'll use:
a.__setattr__(h eight, new_value)
Thanks to all
Mathieu
On Thu, Sep 4, 2008 at 12:25 AM, Mathieu Prevot
<mathieu.prevot @gmail.comwrote :
>
You should subclass 'object', so that should be:
class Foo(object):
>
>
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.
>
Regards,
Chris
<mathieu.prevot @gmail.comwrote :
>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():
>>
>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():
You should subclass 'object', so that should be:
class Foo(object):
>
> width = 10
> height = 20
>>
>a=foo()
>arg='height'
>a.__argname_ _= new_value
> height = 20
>>
>a=foo()
>arg='height'
>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.
>
Regards,
Chris
I'll use:
a.__setattr__(h eight, new_value)
Thanks to all
Mathieu
Comment