[Chicago] class continued, or metaclassing + framehackery, or an exercise in never using this because it's BAD... but fun.
Pete
pfein at pobox.com
Fri Mar 28 20:06:48 CET 2008
I don't get it.
On Mar 27, 2008, at 5:07 PM, Brantley Harris wrote:
> import sys
>
> class ContinueMeta(type):
> def __new__(cls, name, bases, dct):
> if name == 'continued':
> return type.__new__(cls, name, bases, dct)
> existing = sys._getframe(1).f_locals[name]
> for k, v in dct.items():
> setattr(existing, k, v)
> return existing
>
> class continued(object):
> __metaclass__ = ContinueMeta
>
> ### Testing ###
> class Widget(object):
> def __init__(self):
> print "Widget created!"
>
> class Widget(continued):
> def hello(self):
> print "Hello world!"
>
> ----------
>>>> w = Widget()
>>>> w.hello()
> Widget created!
> Hello world!
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago
Pete
pfein at pobox.com
More information about the Chicago
mailing list