from pyswip import Prolog prolog = Prolog() prolog.assertz("father(michael,john)") prolog.assertz("father(michael,gina)") list(prolog.query("father(michael,X)")) == [{'X': 'john'}, {'X': 'gina'}] for soln in prolog.query("father(X,Y)"): print(soln["X"], "is the father of", soln["Y"])
首先需要對庫pyswip進行安裝 pip install pyswip
安裝好之后 在eclipse中創建一個python工程
創建一個名為 test1.py的python文件 輸入如下代碼 測試是否可以使用庫pyswip 進行prolog編程
輸出結果為: