Python dynamic attribute creation

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Jun 26 21:06:38 EDT 2010


On Sat, 26 Jun 2010 10:10:39 -0700, Stephen Hansen wrote:

> This characterization of adding attributes to an object as something
> "else", some special kind of activity called "metaprogramming" I think I
> reject outright, whereas I believe -- though I do not claim to speak for
> him/her -- the OP's position is that using 'syntax' to add attributes is
> actually a special case/activity.
> 
> I consider it the standard, normal behavior.

+1

[...]
> 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.

In fairness, the reason the other languages do so is probably so that the 
compiler can make optimizations leading to faster code, which is why 
CPython is a fairly plodding implementation. But that's due to the 
conservativeness of CPython: Unladen Swallow is faster, and PyPI is 
faster still, and the PyPI people expect to eventually be competitive 
with C for speed.


> Python lets you associate significance with normal events so you can get
> things done. But its just plodding along not really drinking whatever
> kool-aid you are, though its happy you like your flavor and is entirely
> content with letting you think its playing ball with you on that.

Nice :)



-- 
Steven



More information about the Python-list mailing list