简体   繁体   English

python-为什么我的程序告诉我它不可调用

[英]python- why does my program tells me it's not callable

I made a class in python and when I tried to call it into another python file (after importing it) it doesn't recognizes it as a class but as an object and then it tells me that my class is not callable我在 python 中创建了一个类,当我尝试将它调用到另一个 python 文件中时(在导入它之后)它不会将它识别为一个类而是一个对象,然后它告诉我我的类不可调用

here is my class:这是我的课:

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

and here is where I tried to call it:这是我试图称呼它的地方:

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)

and finally here is the error:最后这里是错误:

x=Cell()
TypeError: 'module' object is not callable

can anyone help me fix this, even my teacher didn't understand my mistake谁能帮我解决这个问题,即使我的老师也不明白我的错误

The Cell has been used for both your imported module and your class. Cell已用于您导入的模块和您的类。 According to the error, python has mapped it to the module name.根据错误,python已经将其映射到模块名称。 So, when you are writing Cell() , it tries to use the module name as a function, instead of calling the class constructor.因此,当您编写Cell() ,它会尝试将模块名称用作函数,而不是调用类构造函数。

If the class Cell is inside the Cell module, use Cell.Cell() instead, or change your import to from Cell import Cell .如果类CellCell模块内,请改用Cell.Cell() ,或者将导入更改为from Cell import Cell Otherwise, rename either the module or the class.否则,重命名模块或类。

Your import statement is wrong, you're importing a module called Cell instead of your Cell class.您的导入语句是错误的,您正在导入一个名为 Cell 的模块而不是您的 Cell 类。 You should use lower case for your filenames and import it like so:您应该使用小写作为文件名并像这样导入:

from cell import Cell


test = Cell()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python - 为什么我的可执行程序在使用 pyinstaller 创建后需要很长时间才能加载? - Python- Why does my executable program take a long time to load after creating it with pyinstaller? Python-卡在猜谜游戏的程序上了吗? - Python- Stuck on a guessing game's program? Python Caesar Cipher 风格程序:为什么 python 给我不支持的操作数类型的 TypeError? - Python Caesar Cipher style program: Why does python give me TypeError of unsupported operand type(s)? 为什么Eclipse每次尝试运行我的Python程序时都会要求&#39;ant build&#39;? - Why does Eclipse ask me to 'ant build' every time I try to run my Python program? 为什么我的独立程序退出而不给我机会阅读结果(python)? - Why does my standalone program exits without giving me a chance to read the results (python)? 为什么我的程序要求我在继续之前按回车键(python tkinter) - Why does my program require me to press the enter key before continuing (python tkinter) python- TypeError:func必须是可调用的 - python- TypeError: func must be callable 为什么我的 openpyxl WorkBook.active() 给我一个 TypeError: Object is not callable? - Why does my openpyxl WorkBook.active() give me a TypeError: Object is not callable? 为什么内置函数在 python 中没有被归类为可调用的,我怎样才能让它们在我的程序中显示为可调用的? - Why aren't builtin functions classified as callable in python and how can I make them appear callable in my program? 有没有一种方法告诉我的程序退出? - Is there a method that tells my program to quit?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM