0

今天,出现了一些意想不到的行为。当我写这个时:

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
4

1 回答 1

1
errorLog= ErrorLog["Apple Computers needed, but no OS available"]

你用了括号。您需要括号来创建对象:

errorLog= ErrorLog("Apple Computers needed, but no OS available")
于 2014-04-17T02:25:51.057 回答