Janus and Python properties

Hi all.

I’m at a loss about what I should do here:

?- py_call(blessed:'Terminal',B), py_call(B:height,H).
B = <py_type>(00000205cb85ad30),
H = <py_property>(00000205cbd63740).

I’m trying to access the height property of the Terminal() class from the blessed package (“not only” a wrapper around ncurses).

In Python I just get the height directly like this:

Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import blessed
>>> term = blessed.Terminal()
>>> term.height
56

I tried wrapping H to str() and printing it and a bunch of other tricks I could think of but that doesn’t work. How do I access the value of a Python property with Janus?

Try

?- py_call(blessed:'Terminal'():height, X).
X = 32.

Note that blessed:'Terminal' gives you the function, not the value it evaluates to. If you want two steps:

?- py_call(blessed:'Terminal'(), Term), py_call(Term:height, H).

But, in general, try to avoid intermediate result. They cause objects to be garbage collected, but after a delay. You may also need the option py_object(true) to avoid the intermediate result being translated to Prolog. Whether or not you need that depends on the object type, but if you want an object reference, the safe way is to use this option.

3 Likes

Thanks, I just figured out the right syntax to call Terminal() but the rest would have taken me a while to figure out.

I’m trying to draw on the terminal from Prolog, calling Python. That’s gonna be fun.