B
Bruno Desthuilliers
George Sakkis a écrit :
Good point. There are effectively a couple of things that did work with
the old object model and don't with the new one. OTOH, and while I tend
to make heavy use of Python's dynamism and advanced features, I never
had the need to dynamically override special methods on a per-instance
basis yet. Not to say this is useless, just that it's probably enough of
a corner case to justify the design choice (YMMV of course).
FWIW, I am not advocating old style classes and I rarely (if ever) use
them in new code, but I occasionally miss the following feature, which
by the way disproves the assertion that "new-style classes can do
anything Classic classes did":
class Classic: pass
class NewStyle(object)ass
for o in Classic(),NewStyle():
o.__str__ = lambda: 'Special method overriding works on
instances!'
print '%s object: %s' % (o.__class__.__name__, o)
Good point. There are effectively a couple of things that did work with
the old object model and don't with the new one. OTOH, and while I tend
to make heavy use of Python's dynamism and advanced features, I never
had the need to dynamically override special methods on a per-instance
basis yet. Not to say this is useless, just that it's probably enough of
a corner case to justify the design choice (YMMV of course).