Python dynamic attribute creation

WANG Cong xiyou.wangcong at gmail.com
Thu Jul 1 10:31:29 EDT 2010


On 06/30/10 01:20, Stephen Hansen <me+list/python at ixokai.io> wrote:

>> But if so why setattr() still exists? What is it for if we can do the
>> same thing via assignments? Also, in order to be perfect, Python should
>> accept to add dynamic attributes dynamically, something like PEP
>> 363. That doesn't happen.
>
> What does perfection have to do with anything? Python does not strive
> for perfection. More then that, it rejects the entire idea of
> perfection when it gets in the way of simply solving problems in an
> easy, clean, readable, and reliable way. "Practicality beats purity".
>


I don't quite understand the spirit behind. IMHO, being purity should
not harm the practicality, they are harmonious. :)

> PEP 363 proposes adding new syntax: for new syntax to be accepted into
> the language one must meet a *very* high bar. One must show a clear,
> compelling reason why this new mental burden is worth increasing the
> complexity of the language.
>
> Syntax won't get added to make the language more "perfect" to some
> ideals (especially not ideals to some paradigm like OOP, as opposed to
> its own internal ideals of readability, ease and practicality).
>
> Syntax is a burden. Every change in syntax, every addition in syntax,
> requires everyone's to mental investment to increase: it costs more
> mental energy to use the language, to fully understand it, then it did
> before.
>


But how could the syntax could be a burden? It is easy to
understand. And the reason why needs it is also clear, making class
attributes more like a dictionary, isn't this why people insists we
should have dynamic attribute creation via assigments?

This seems to be unfair. :)

>
> Is Python perhaps less perfect, pure, with that addition to the
> language denied?
>
> Who cares? Perfection is what the Borg* worship, I like understandable. :)

Well, using setattr() rather than trivial assignments is also
understandable, in fact, for me the former is even more understandable,
it shows more clearly when I am adding a new attribute, I am programming
classes, not non-classes.

-- 
Live like a child, think like the god.
 



More information about the Python-list mailing list