Python binding


The python vocab and its subvocabs implements a simple binding for libpython, allowing factor code to call native python.

Converting to and from Python:
>py ( obj -- py-obj )

py> ( py-obj -- obj )

quot>py-callback ( quot: ( args kw -- ret ) -- alien )


Error handling:
python-error ( type message traceback -- * )


Initialization and finalization:
py-initialize ( -- )

py-finalize ( -- )


Module management:
py-import ( modulename -- module )


The vocab python.syntax implements a higher level factorific interface on top of the lower-level constructs in this vocab. Prefer to use that vocab most of the time.

Notes
Sometimes the embedded python interpreter can't find or finds the wrong load path to it's module library. To counteract that problem it is recommended that the PYTHONHOME environment variable is set before py-initialize is called. E.g:
"C:/python27-64bit/" "PYTHONHOME" set-os-env


Warning
All code that calls Python words should always be wrapped in a with-destructors context. The reason is that the words add references to Pythons internal memory heap which are removed when the destructors trigger.