Public feed #601593

metaclass example

public python v1 · immutable
Raw Edit
·published 2007-07-03 16:38 UTC
rendered paste body
def DynamicDocstringMeta(reps):    def __new__(cls, name, bases, attrs):        attrs['__doc__'] = attrs['__doc__'] % reps        return type.__new__(cls, name, bases, attrs)    return type('', (type, ), {'__new__': __new__})# test scenarioclass Test(object):    """This docstring can change! (%s, %d)"""    __metaclass__ = DynamicDocstringMeta(('test', 3))>>> Test().__doc__'This docstring can change! (test, 3)'