Python dynamic attribute creation

Stephen Hansen me+list/python at ixokai.io
Thu Jul 1 11:19:50 EDT 2010


On 7/1/10 8:02 AM, WANG Cong wrote:
> On 06/27/10 09:06, Steven D'Aprano<steve at REMOVE-THIS-cybersource.com.au>  wrote:
>
>>> In that situation, certainly: adding an attribute on the fly to that
>>> formal definition seems entirely strange and special of an activity. But
>>> that's only because you *chose* to *see* and *use* the object that way.
>>> The "special"ness of the activity is entirely in your head, and to
>>> Python, its an entirely normal event.
>>
>> Exactly. Things which other languages make scary and mysterious
>> "metaprogramming" are, in Python, normal and ordinary programming. It
>> doesn't seem to do us any harm.
>>
>
> As long as setattr() exists in Python, that will be not so ordinary. :)

setattr is perfectly ordinary.

-- 

    ... Stephen Hansen
    ... Also: Ixokai
    ... Mail: me+list/python (AT) ixokai (DOT) io
    ... Blog: http://meh.ixokai.io/




More information about the Python-list mailing list