Pyq => Embedpy transition

https://learninghub.kx.com/forums/topic/pyq-embedpy-transition

Hello!

I used to use Pyq to call a python function within my q code.I definied a python function in a .p file, at the end of the file, used .q.name_of_fun= name_of_fun, nd then was able to call it from my q code directly in my q code.

I am struggling to do the equivalent using embedpy (note that this is a long function and i would prefer not to define it within my q file). The matplotlib example in the embedpy doc does not cover this issue, as it simply launches the .p file but not using any q date in it.

also, at some point, i used to do :

p)import sys

p)sys.path.append(str(q.lib_path))

where lib_path was a string "Path/to/a/lib"

i dont find the equivalent in embedpy

Thank you for your help!

embedPy operates in a q first manner so you’d have to load your .p file and then call a q statement outside to do the assignment:

https://github.com/KxSystems/embedPy/tree/master/docs

q)func:.p.get[`func]

PyKX is the most flexible interface as it allows you do mix q first and Python first code in the same project

https://code.kx.com/pykx/2.5/

Python first assign a python function to a q variable

>>> kx.q['func'] = func

q first assign a python function to a q variable:

https://code.kx.com/pykx/2.5/pykx-under-q/intro.html#function-calls

q)func:.pykx.get[`func]