5 Calling Prolog from Python
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • SWI-Prolog Python interface
        • Calling Prolog from Python
          • Janus iterator query
          • Janus iterator apply
          • Janus access to Python locals and globals
          • Janus and Prolog truth
          • Janus class Term
          • Janus class PrologError

5.5 Janus class Term

Class janus.Term() encapsulates a Prolog term. Similarly to the Python object reference (see py_is_object/1), the class allows Python to represent arbitrary Prolog data, typically with the intend to pass it back to Prolog.

Term janus.Term(*args)
Instances are never created explicitly by the user. An instance is created by handling a term prolog(Term) to the data conversion process. As a result, we can do
?- py_call(janus:echo(prolog(hello(world))), Obj,
           [py_object(true)]).
Obj = <py_Term>(0x7f7a14512050).
?- py_call(print($Obj)).
hello(world)
Obj = <py_Term>(0x7f7a14512050).
Term janus.Term.__str__()
Return the output of print/1 on the term. This is what is used by the Python function print().
Term janus.Term.__repr__()
Return the output of write_canonical/1 on the term.