def enableAttributes(genfunc):
"""Wrapper for generators to enable classlike attribute access.
The generator definition should specify 'self' as the first parameter.
Calls to a wrapped generator should ignore the self parameter.
"""
old = getargspec(genfunc)
old[0].pop(0)
new = getargspec(genfunc)
new[0][0] = 'wrapped'
specs = {'name': genfunc.func_name,
'oldargs': formatargspec(*old),
'newargs': formatargspec(*new)}
exec(_redefinition % specs, genfunc.func_globals)
#### A minimal, complete example
评论列表
文章目录