Can (should) this be rewritten without exec?
Berthold Höllmann
bhoel at web.de
Wed Jun 9 15:25:54 EDT 2004
Hello,
I do need some code that does someting like
--- snip ---
class X(object):
def a(*arg, **kw):
"""This is test a"""
print "func a", arg, kw
a=staticmethod(a)
def b(*arg, **kw):
"""This is test b"""
print "func b", arg, kw
b=staticmethod(b)
def __wrapper(func, *arg, **kw):
func.__doc__
print "start wrapper"
func(*arg, **kw)
print "done wrapper"
for c in ['a', 'b']:
exec "%s = lambda *arg, **kw : __wrapper(X.%s, *arg, **kw)" % (c, c)
exec "%s.__doc__ = X.%s.__doc__" % (c, c)
print a.__doc__
a(1, 2, 3, d=4, e=5, f=6)
b(1, 2, 3, d=4, e=5, f=6)
--- snap ---
Can this be rewritten without using 'exec'. In my real case 'X' is an
extension module if that matters.
Thanks
Berthold
--
bhoel at web.de / http://starship.python.net/crew/bhoel/
More information about the Python-list
mailing list