今天,出现了一些意想不到的行为。当我写这篇文章时:
class ErrorPost(object):
def __init__(self, message):
self.message = "[Error]" + message
print(self.message)
del self
class ErrorLog(ErrorPost):
def __init__(self, message):
super().__init__(message)
del self
创建ErrorLog对象时,此代码会引发错误:
TypeError: 'type' object is not subscriptable
这是为什么?我没有操纵任何类型的东西,也没有尝试将对象变成另一种类型,例如int。发生了什么,这里?
我可以发布的代码数量有限,抱歉。
完整堆栈跟踪:
C:\Python33\python.exe C:/Users/******/Documents/MalwareTycoon/main.py
Traceback (most recent call last):
File "C:/Users/******/Documents/MalwareTycoon/main.py", line 151, in generate_network
********Dict[self.*********] = ***(self.available*****Dict[randint])
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/******/Documents/MalwareTycoon/main.py", line 201, in <module>
Game = Game()
Image loaded: C:/Users/******/Documents/MalwareTycoon\images\background.PNG
File "C:/Users/******/Documents/MalwareTycoon/main.py", line 58, in __init__
self.computers = self.generate_network()
File "C:/Users/******/Documents/MalwareTycoon/main.py", line 153, in generate_network
errorLog= ErrorLog["Apple Computers needed, but no OS available"]
TypeError: 'type' object is not subscriptable
Process finished with exit code 1
答案 0 :(得分:1)
errorLog= ErrorLog["Apple Computers needed, but no OS available"]
您使用了括号。您需要括号来创建对象:
errorLog= ErrorLog("Apple Computers needed, but no OS available")