我正在使用Python进行工作,我需要在类中编写一个函数,例如:
class asas(object):
def b(self):
self.name = "Berkhan"
a = asas()
a.b().name
我检查了这个模块。
Traceback (most recent call last):
File "C:\Users\Berkhan Berkdemir\Desktop\new 1.py", line 5, in <module>
a.b().name
AttributeError: 'NoneType' object has no attribute 'name'
我该怎么办?
name
是实例的属性,所以你应该先执行a.b()
,然后在第二步执行print(a.name)
。 - Matthias