Python dynamic attribute creation
Ethan Furman
ethan at stoneleaf.us
Tue Jun 29 13:25:42 EDT 2010
WANG Cong wrote:
> On 06/29/10 17:48, Andre Alexander Bell <post at andre-bell.de> wrote:
>
>> As said previously I don't think one should differentiate between meta
>> programming and programming within the language, since the former is
>> nothing different than the latter.
>>
>
> If you check other programming language rather than Python, it is
> different. Even in Ruby which is also a dynamic language.
If Python were going to be the same as other languages, what would be
the point of having Python?
>> So far I only did tell you _how_ it is in Python. If I understand your
>> question about the design of the language correctly than you would like
>> Python to detect the typo. Let's for the moment assume that the
>> declaration would be decoupled from assigning a value.
>
> Nope, I would like Python not to allow adding a new attribute via an
> assignment by default, detecting the typo is a side-effect.
I, for one, am very happy that Python allows it -- if I wanted to jump
through hoops for simple things I'd use some other language.
> 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.
Setattr and friends exist to work with dynamic attributes.
"The Perfect Language" does not exist, and never will. I'm not even
sure it could exist for a single person, let alone a group of people
with disparate needs, patterns of thought, etc.
~Ethan~
More information about the Python-list
mailing list