Hello,
I'm beginning to use pyswip and I've encountered an error when consulting a file.
On windows, the python Path contains backslash (even if I replace them in the parameters), and single backslash in the consult query are interpreted as escape.
ERROR: Syntax error: Unknown character escape in quoted atom or string: `\D'
ERROR: consult('C:
ERROR: ** here **
ERROR: \Develop\pyswip-mastermind\src\prolog\
mastermind.pl') .
Traceback (most recent call last):
File "C:\Develop\pyswip-mastermind\src\main.py", line 20, in <module>
prolog.consult(relative_to=prolog_relative_to,path='prolog/
mastermind.pl')
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Develop\pyswip-mastermind\.venv\Lib\site-packages\pyswip\prolog.py", line 393, in consult
next(cls.query(str(path).join(["consult('", "')"]), catcherrors=catcherrors))
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Develop\pyswip-mastermind\.venv\Lib\site-packages\pyswip\prolog.py", line 171, in __call__
raise PrologError(
...<10 lines>...
)
pyswip.prolog.PrologError: Caused by: 'consult('C:\Develop\pyswip-mastermind\src\prolog\
mastermind.pl')'. Returned: 'error(syntax_error(undefined_char_escape(D)), string(b"consult('C:\\Develop\\pyswip-mastermind\\src\\prolog\\
mastermind.pl') . ", 11))'.
I've tested with the master gron git, installed by pip install (not sur I dit it well, I'm a beginner)
In fact the solution should be simple.
the backslash should be doubled
in prolog.consult()
path = resolve_path(path, relative_to)
next(cls.query(str(path).join(["consult('", "')"]), catcherrors=catcherrors))
it should become
path = resolve_path(path, relative_to)
next(cls.query(str(path).replace('\\','\\\\').join(["consult('", "')"]), catcherrors=catcherrors))
What do yo think ?
I'm a bit noob I admit.