class A:
def __init__(self):
self.name = 'test'
def method(self):
print("method print")
Instance = A()
print(getattr(A, 'method', 'default')())
上面这段代码输出如下,请问要怎么修改才能使得 print 语句可以显示 method 函数的执行结果呢?谢谢
Traceback (most recent call last):
File "d:\Python3\t1.py", line 9, in
print(getattr(A, 'method', 'default')())
TypeError: method() missing 1 required positional argument: 'self'
def __init__(self):
self.name = 'test'
def method(self):
print("method print")
Instance = A()
print(getattr(A, 'method', 'default')())
上面这段代码输出如下,请问要怎么修改才能使得 print 语句可以显示 method 函数的执行结果呢?谢谢
Traceback (most recent call last):
File "d:\Python3\t1.py", line 9, in
print(getattr(A, 'method', 'default')())
TypeError: method() missing 1 required positional argument: 'self'