On 06/25/10 15:34, Bruno Desthuilliers 
<bruno.42.desthuilli...@websiteburo.invalid> wrote:

> WANG Cong a écrit :
>> Hi, list!
>>
>> I have a doubt about the design of dynamic attribute creation by
>> assignments in Python.
>>
>> As we know, in Python, we are able to create a new attribute of
>> a class dynamically by an assignment:
>>
>>>>> class test: pass
>> ... 
>>>>> test.a = "hello"
>>>>> test.a
>> 'hello'
>>
>> However, I still don't get the points why Python designs it like this.
>>
>> My points are:
>>
> (snip)
>
> Python's classes are plain objects, and like any other object are
> created at runtime. Having to special-case them would break the
> simplicity and uniformity of Python for no good reason. Just like
> there's no good reason to make setattr() working differently for class
> and non-class objects.
>

For implementaiton, perhaps, but not for the language design, how could
a language design be perfect if we can use setattr() like assignments
while use other things, e.g. delattr(), not? Is there any way to express
delattr() as simple as expressing setattr() with assignments? I doubt...

Using assignments to create an attribute hides metaprogramming behide,
while using delattr() exposes it.

Thanks!

-- 
Live like a child, think like the god.
 
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to