【发布时间】:2020-01-15 17:02:26
【问题描述】:
class lights(object):
l1 = lights()
l1.color = "blue"
l1.quantity = 50
l2 = lights()
l2.color = "red"
l2.quantity = 50
AttributeError Traceback (most recent call last)
<ipython-input-11-1ae6b23b2a3d> in <module>
----> 1 class lights(object):
2 l1 = lights()
3 l1.color = "blue"
4 l1.quantity = 50
5
在灯()中 1类灯(物体): 2 l1 = 灯() ----> 3 l1.color = "蓝色" 4 l1.数量 = 50 5
AttributeError: 'NoneType' object has no attribute 'color'
【问题讨论】:
-
lights甚至不应该被定义。这显然重新定义了lights,它以前是一个在调用时返回None的函数。 -
显示更多代码可能会有所帮助。
-
你想做什么?这段代码有一些问题,可能有助于理解您的主要目标以便更好地帮助...
-
这能回答你的问题吗? How can I define a class in Python?