【发布时间】:2019-03-09 13:01:42
【问题描述】:
我在 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
谁能帮我解决这个问题,即使我的老师也不理解我的错误
【问题讨论】:
-
你可能需要使用
from cell import Cell -
我认为你应该像
from <your_module_name> import Cell这样导入你的类 -
Cell.Cell()或from Cell import Cell -
该问题不可重现。
-
您导入了一个模块。模块不可调用。
标签: python xcode python-2.7 debugging helper