2
我很惊讶方法中函数参数的名称空间是类而不是全局作用域。方法参数中的命名空间
def a(x):
print("Global A from {}".format(x))
class Test:
def a(self, f=a):
print("A")
f("a") # this will call the global method a()
def b(self, f=a):
print("B")
f("b") # this will call the class method a()
t=Test()
t.b()
如何解释?而我将如何从b的参数访问全局a()?
谢谢!这样可行。然而,对于我来说,参数命名空间与方法代码中的命名空间不同... – Gerenuk
是的,在我习惯之前,它对我来说也是意外的。 – agf