from pyswip import Prolog
prolog = Prolog()
prolog.assertz(u"father('franišek')")
prolog.assertz(u"father('bonifác')")
print(list(prolog.query("father(X)")))
[{'X': 'franišek'}, {'X': 'bonifác'}]
:- set_prolog_flag(encoding,utf8).
father('franišek').
father('bonifác').
from pyswip import Prolog
prolog = Prolog()
prolog.consult("test.pl", catcherrors=True)
print(list(prolog.query("current_prolog_flag(encoding,X)")))
print(list(prolog.query("father(X)")))
[{'X': 'utf8'}]
File "d:\xwrk\sandbox\prolog\test_pyswip.py", line 6, in <module>
print(list(prolog.query("father(X)")))
File "D:\xprg\python\Conda35\Lib\site-packages\pyswip\prolog.py", line 111, in __call__
t = getTerm(swipl_list)
File "D:\xprg\python\Conda35\Lib\site-packages\pyswip\easy.py", line 404, in getTerm
res = getList(t)
File "D:\xprg\python\Conda35\Lib\site-packages\pyswip\easy.py", line 420, in getList
result.append(getTerm(head))
File "D:\xprg\python\Conda35\Lib\site-packages\pyswip\easy.py", line 406, in getTerm
res = getFunctor(t)
File "D:\xprg\python\Conda35\Lib\site-packages\pyswip\easy.py", line 429, in getFunctor
return Functor.fromTerm(t)
File "D:\xprg\python\Conda35\Lib\site-packages\pyswip\easy.py", line 254, in fromTerm
return cls(f.value, args=args, a0=a0)
File "D:\xprg\python\Conda35\Lib\site-packages\pyswip\easy.py", line 231, in __init__
self.__value = self.func[self.handle](self.arity, *self.args)
File "D:\xprg\python\Conda35\Lib\site-packages\pyswip\easy.py", line 295, in _unifier
return {args[0].value:args[1].value}
File "D:\xprg\python\Conda35\Lib\site-packages\pyswip\easy.py", line 82, in get_value
ret = ret.decode()
builtins.UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 5: invalid continuation byte
In the project SWI-prolog loading of the test.pl file works without a problem.
Thank you very much for the inspiration, how to find a solution to the problem?.