[英]Python- Why does my executable program take a long time to load after creating it with pyinstaller?
[英]python- why does my program tells me it's not callable
我在 python 中创建了一个类,当我尝试将它调用到另一个 python 文件中时(在导入它之后)它不会将它识别为一个类而是一个对象,然后它告诉我我的类不可调用
这是我的课:
class Cell:
def __init__(self,value=9,isVissible=False):
self.value=value
self.isVisible=isVissible
def setValue(self,value):
self.value=value
def setVisible(self):
self.visible=True
这是我试图称呼它的地方:
import Cell,random
class Board:
def __init__(self):
self.board = []
for i in range(12):
a = []
for j in range(12):
x = Cell() <=== right here it's an error
.
.
.(the rest of my program)
最后这里是错误:
x=Cell()
TypeError: 'module' object is not callable
谁能帮我解决这个问题,即使我的老师也不明白我的错误
Cell
已用于您导入的模块和您的类。 根据错误,python已经将其映射到模块名称。 因此,当您编写Cell()
,它会尝试将模块名称用作函数,而不是调用类构造函数。
如果类Cell
在Cell
模块内,请改用Cell.Cell()
,或者将导入更改为from Cell import Cell
。 否则,重命名模块或类。
您的导入语句是错误的,您正在导入一个名为 Cell 的模块而不是您的 Cell 类。 您应该使用小写作为文件名并像这样导入:
from cell import Cell
test = Cell()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.