about 'setattr(o, name, value)' and 'inspect.signature(f)'

Ned Batchelder ned at nedbatchelder.com
Tue Oct 10 13:36:32 EDT 2017


On 10/10/17 11:00 AM, Stefan Ram wrote:
> xieyuheng <xyheme at gmail.com> writes:
>> 1. 'setattr(o, name, value)' can be used for what kind of objects ?
>    It takes three objects as arguments.
>
>    The first object should have an attribute named by the value
>    of »name« that should allow this attribute to be set to
>    »value« as if by
>
> o.<name>=value
>
>    where <name> is the value of »name« (which should be a string).
>

One tweak to this: the object doesn't need to have the attribute 
initially.  setattr() can create new attributes that don't already exist.

--Ned.



More information about the Python-list mailing list