我目前正在使用 pyCLIPS 在 python 中编写程序。
clips 模块允许我简单地使用以下命令将多行输出打印到终端:clips.PrintFacts()
但是,我想将其输出到文件以保存结果。我正在使用以下代码:
def Print():
f1=open('/var/log/combined/test.log', 'a')
print >>f1, '- Facts -\n'
print >>f1, clips.PrintFacts()
print >>f1, '\n- Rules -\n'
print >>f1, clips.Print.Rules()
第一个和第三个打印命令成功地将它们的字符串打印到文件中,但第二个和第四个打印命令仍然只将剪辑结果输出到终端。下面是一个输出示例:
=============
root@ubuntu:/home/user/Desktop# python program.py
f-0 (initial-fact)
f-1 (duck)
f-2 (quack)
For a total of 3 facts.
MAIN:
Rule1
Rule2
Rule3
Rule4
Rule5
root@ubuntu:/home/user/Desktop# cat /var/log/combined/test.log
- Facts -
None
- Rules -
None
root@ubuntu:/home/user/Desktop#
=============
该clips.PrintFacts()
部分从“f-0”开始,而clips.PrintRules()
从“MAIN”开始。
提前致谢!