我知道以前可能会问过这个问题,但是我确实需要一个很好的答案。
我的代码:
import random
objects = []
class test_object:
def __init__ (self, x, y):
self.x = x
self.y = y
def draw(self):
print(test)
while 1==1:
for test_object in objects:
test_object.x = random.randint(1,10)
objects.append(test_object(1,2)) ### Error occurs here.
而且我得到TypeError:'test_object'对象不可调用。有人可以解释为什么会发生这种情况以及如何解决它,这种情况只有在我尝试将对象附加到数组时才会发生。