Python 程序调用序言并打印序言输出

Python program calling prolog and print prolog output

我是 prolog 的新手,我有一个 python 程序,它使用 os.system(prolog_command) 调用 prolog 并得到结果(真或假),但我想要我的程序在控制台中显示相同的结果(prolog 写入的行)。 有人可以帮我吗?

提前致谢。

我试过这个简单的方法:

foo.pl 的内容:

foo :- write('hello, world'), nl.

然后在python:

>>> import commands
>>> commands.getoutput('echo "foo." | swipl -q -f foo.pl')
'hello, world\ntrue.\n\n'
>>> x = commands.getoutput('echo "foo." | swipl -q -f foo.pl')
>>> x
'hello, world\ntrue.\n\n'
>>>