【发布时间】:2020-05-23 02:46:23
【问题描述】:
你好,
我使用 Python 3.8.3 在 Conda 环境中安装了 Experta,我的所有程序都可以正常工作,但是当我尝试运行此代码导入 Experta 库时,我遇到以下错误:“NameError: name 'Fact' is not defined”。
from random import choice
from experta import *
class Light(Fact):
"""Info about the traffic light."""
pass
class RobotCrossStreet(KnowledgeEngine):
@Rule(Light(color='green'))
def green_light(self):
print("Walk")
@Rule(Light(color='red'))
def red_light(self):
print("Don't walk")
@Rule(AS.light << Light(color=L('yellow') | L('blinking-yellow')))
def cautious(self, light):
print("Be cautious because light is", light["color"])
engine = RobotCrossStreet()
engine.reset()
engine.declare(Light(color=choice(['green', 'yellow', 'blinking-yellow', 'red'])))
engine.run()
错误:
Traceback (most recent call last):
File "experta.py", line 2, in <module>
from experta import *
File "/home/karuro/Documents/Magierin/UPN/IntelligentSystems/Experta/experta.py", line 5, in <module>
class Light(Fact):
NameError: name 'Fact' is not defined
谁能帮我解决这个问题?
【问题讨论】:
-
你真的不应该这样做
from experta import *加星标的导入是不好的。我不熟悉这个库,我只能推测你希望它包含Fact,但显然它没有。为什么你认为应该这样做? -
等等,你把文件命名为
experta.py了吗?不要那样做,那会影响您安装的库。请始终将完整的错误消息发布为格式化文本 I。问题本身*请勿发布图片/屏幕截图或链接。 -
@juanpa.arrivillaga 它通过使用另一个名称复制文件来工作。感谢您的帮助和建议,我编辑问题以文本格式显示错误。
标签: python import conda nameerror python-3.8