对象模块不可调用,constan上的语法无效

2024-10-01 04:56:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手。我得到了Syntax Error: invalid syntax & object module is not callable

谢谢你的帮助

在Spot.py在

class Spot(object):
    isBunny = bool()
    UP = 0
    SLEEP = 2

    def __init__(self, newIsBunny):
        self.isBunny = newIsBunny
        self.nextCycle = self.UP

在测试.py在

^{pr2}$

Tags: pyselfobjectisnoterrormodulesyntax
2条回答

除了Borgleader说的,而不是

import Spot

使用

^{pr2}$

这将修复“模块不可调用”错误。在

当你说

import Spot

那么“Spot”就是整个模块。点。点是Spot模块中的Spot类,这正是您真正想要的。使用from Spot import Spot语法可以让您只从Spot模块中提取Spot类,并将其称为Spot。在

首先,类中的代码应该缩进。这就是python知道代码是类的一部分的方式(与缩进告诉python哪个代码是函数或循环的一部分一样)。在

其次,你在if i==Spot.SLEEP后面错了一个:

相关问题 更多 >