Both strings and pathlib.Path objects are allowed as paths
from pathlib import Path
Prolog.consult(Path("myfile.pl"))
# equivalent to:
Prolog.consult("myfile.pl")
Added relative_to keyword argument
relative_to keyword argument makes it easier to construct the consult path.
This keyword is no-op, if the consult path is absolute.
If the given relative_to path is a file, then the consult path is updated to become a sibling of that path.
Assume you have the /home/me/project/facts.pl that you want to consult from the run.py file which exists in the same directory /home/me/project.
Using the built-in __file__ constant which contains the path of the current Python file , it becomes very easy to do that:
# in run.py
Prolog.consult("facts.pl", relative_to=__file__)
If the given relative_path is a directory, then the consult path is updated to become a child of that path.
This PR contains several enhancements to the
Prolog.consult
method.Tilde character in paths are expanded to the user home directory
Both strings and pathlib.Path objects are allowed as paths
Added relative_to keyword argument
relative_to
keyword argument makes it easier to construct the consult path. This keyword is no-op, if the consult path is absolute.If the given
relative_to
path is a file, then the consult path is updated to become a sibling of that path. Assume you have the/home/me/project/facts.pl
that you want to consult from therun.py
file which exists in the same directory/home/me/project
. Using the built-in__file__
constant which contains the path of the current Python file , it becomes very easy to do that:If the given
relative_path
is a directory, then the consult path is updated to become a child of that path.Symbolic links are not yet supported yet.