J. Cliff Dyer wrote:
On Fri, 2009-01-23 at 20:25 -0800, Paul McGuire wrote:
... How about this:
aobj = A()
aobj.__class__ = B
... Wow. That looks very powerful and fun. But scary. Any thoughts
on how you would use that in a way that wouldn't unleash sulphurous
code smells?
Seems like a nice way to transition between "ActiveAccount": and
"InActiveAccount" or some such. The requirement is that the two
classes share memory layout (essentially, class type and all __slots__
involved (including __dict__). It is a bit prickly, so I'd personally
only start to use it once my methods were littered with lots of:
...
if self.active_flag:
self.account.update(...
else:
raise ValueError('Purchase prohibitted')
Could also be useful as the stub for a kept-on-disk structure,
where all methods on the inactive one rolled in data switched class,
and invoked their corresponding method.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list