Python dynamic attribute creation

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sun Jun 27 06:44:31 EDT 2010


WANG Cong a écrit :
(snip)
> 
> The point is why making metaprogramming easy is wonderful?

Because it makes life easier ?-)

> AND, even if
> it were wonderful, why only this one, i.e. creating attributes by
> assignments, not other things?

Like :

class Test(object):
    a = 1

del Test.a

?-)

>>> 2) Metaprogramming should be distinguished with non-meta programming,
>>> like templates in C++, it is obvious to see if you are using template
>>> metaprogramming in C++.
>> Why should it be?
> 
> 
> It is, if you consider other things of metaprogramming in Python. For
> example, deleting an attribute.

cf above.

>>
>>> 3) Thus, allowing dynamic attribute creation by assignment _by default_
>>> is not a good design for me. It is not obvious at all to see if I am
>>> doing metaprogramming at a first glance.
>> Why do you care if you are doing metaprogramming? Perhaps other languages 
>> make it seem difficult and scary, but in Python it is not. It is simple 
>> and easy.
>>
> 
> 
> I do care, programming for a class is quite different from programming
> for a non-class,

Not when a class is just another ordinary object.




More information about the Python-list mailing list