Movatterモバイル変換
[0]ホーム
Deprecate self
Ben Wolfsonwolfson at uchicago.edu
Thu Apr 19 18:11:07 EDT 2001
In article <vQpD6.47756$J%5.15806884 at news2.rdc2.tx.home.com>, "RainerDeyke" <root at rainerdeyke.com> wrote:> "Alex Martelli" <aleaxit at yahoo.com> wrote in message> news:9bkvi30uf8 at news1.newsguy.com...>> "Rainer Deyke" <root at rainerdeyke.com> wrote in message>> news:OLlD6.46125$J%5.15304817 at news2.rdc2.tx.home.com... How do you stop>> a class from having subclasses in Python?>> def f():> class C:> pass> C()>>> from klass import klass>>> def get_atuple(self):return self.atuple>>> def init(self, tup):self.atuple = tup>>> def set_atuple(self, tup):self.atuple = tup>>> TupleHaver = klass({}, {'__init__':init, 'get_atuple':get_atuple, 'set_atuple':set_atuple}) t = TupleHaver((1,2,'hi'))>>> t.get_atuple()(1, 2, 'hi')>>> t.set_atuple(('la la', 'la'))>>> t.get_atuple()('la la', 'la')### part of klass.pydef klass(static_var_dict, methdict): def make(*initv, **initk): inst = lambda: None m = {} for k in methdict.keys(): m[k] = fako(methdict[k], inst) inst.func_dict = m inst.func_dict.update(static_var_dict) m.get('__init__', lambda\ *a, **k: None)(*initv, **initk) return inst return makedef fako(func, inst): return lambda *a, **k: func( *((inst,)+a), **k)-- Barnabas T. RumjugglerThou hast been called, O Sleep! The friend of woe,But 'tis the happy who have called thee so. -- Robert Southey
More information about the Python-listmailing list
[8]ページ先頭