将被调用函数的数据委托给另一个函数很简单:
def test2(a, b):
huh = locals()
print huh
def test(a, b='hoho'):
test2(**locals())
但是,locals()
包含self
何时调用方法,并且在尝试在单行中对方法调用执行相同操作时,这会妨碍:
class X(object):
def test2(self, a, b):
huh = locals()
print huh
def test(self, a, b='hoho'):
self.test2(**locals()) # no workie
test2(**locals()) # no workie either