WANG Cong a écrit :
On 07/01/10 23:19, Stephen Hansen <me+list/pyt...@ixokai.io> wrote:
As long as setattr() exists in Python, that will be not so ordinary. :)
setattr is perfectly ordinary.
If you think setattr() is as ordinary as a trivial assignment,
setattr IS a trivial assignment.
However, I think setattr() is a builtin function, using it exposes the
*magic* of metaprogramming (or class-programming, if more correct) at a
first glance.
No "magic" and no "meta"whatever involved. setattr is as simple as:
def setattr(obj, name, value):
obj.__setattribute__(name, value)
which is *exactly* what gets called when you use the binding statement
form ie "obj.someattr = value" which FWIW is just syntactic sugar for
the former (just like the 'class' statement is just syntactic sugar for
a call to type, etc).
I fail to understand why you insist on seeing something as trivial as
"magic", "metaprogramming" or whatever.
--
http://mail.python.org/mailman/listinfo/python-list