Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading a datalog program in a file into pyDatalog
    primarykey
    data
    text
    <p>I am trying to use the pyDatalog.load() method to load a small pyDatalog program. For example, I am loading the factorial sample from <a href="https://sites.google.com/site/pydatalog/" rel="nofollow">https://sites.google.com/site/pydatalog/</a></p> <pre><code>from pyDatalog import pyDatalog pyDatalog.create_atoms('factorial, N, F') # gives datalog capability to these words def run_program(): N = pyDatalog.Variable() F = pyDatalog.Variable() file_in = open("sample_datalog_program.dl", 'r') mc = file_in.read() print mc @pyDatalog.program() def _(): # the function name is ignored pyDatalog.load(mc) #pyDatalog.load(""" #+ (factorial[1]==1) #(factorial[N] == F) &lt;= (N &gt; 1) &amp; (F == N*factorial[N-1]) #""") print(pyDatalog.ask('factorial[4]==F')) file_in.close() pass if __name__ == "__main__": run_program() </code></pre> <p>the file sample_datalog_program.dl contains the following:</p> <pre><code>""" + (factorial[1]==1) (factorial[N] == F) &lt;= (N &gt; 1) &amp; (F == N*factorial[N-1]) """ </code></pre> <p>What am I doing wrong? When I replace the line pyDatalog.load(mc) by the next 4 commented lines it works fine. </p> <p>The error I get is:</p> <pre><code> /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/bin/python2.7 run_datalog_program.py pyDatalog version 0.12.0 Traceback (most recent call last): File "run_datalog_program.py", line 25, in &lt;module&gt; run_program() File "run_datalog_program.py", line 11, in run_program @pyDatalog.program() File "/usr/local/lib/python2.7/site-packages/pyDatalog/pyParser.py", line 191, in add_program load(source_code, newglobals, defined, function=func_name) File "/usr/local/lib/python2.7/site-packages/pyDatalog/pyParser.py", line 154, in load six.exec_(code, newglobals) File "/usr/local/lib/python2.7/site-packages/six.py", line 308, in exec_ exec("""exec code in globs, locs""") File "&lt;string&gt;", line 1, in &lt;module&gt; File "_", line 1, in &lt;module&gt; File "/usr/local/lib/python2.7/site-packages/pyDatalog/pyDatalog.py", line 115, in load return pyParser.load(code) File "/usr/local/lib/python2.7/site-packages/pyDatalog/pyParser.py", line 133, in load spaces = r.match(line).group() TypeError: expected string or buffer """ + (factorial[1]==1) (factorial[N] == F) &lt;= (N &gt; 1) &amp; (F == N*factorial[N-1]) """ Process finished with exit code 1 </code></pre> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload