Send python object to KDB

Hello, 

I am using pyQ and KDB on a server and I try to pass a variable in a Q function. So I have something like that 

from pyq import q 

%q h: hopen(hostnameport`login)

%q h “myfunc : { x*x}”

If I do 

%q  h “x:2”

%q h “res:myfunc 

I extracting res to a python object is easy but what I want is to give:

x=2 (python var)

%q h “res:myfunc 

Is that possible ? 

Many thanks

Hi Michel,

So to do this you need to map the python object to a kdb one by assigning - see here, so you would do something like this in your pyQ session:

>>> q.x = 2

Which creates a variable in q called x.

Looks like you’re defining the functions and the results on the remote q processes - just wanted to check if you’re meaning to do that? For example if what you wanted was to pull the results from the function execution into the pyq session you could do something like this:

%q h: hopen(hostnameport`login)

%q h “myfunc : { x*x}”

%q res: h (`myfunc;x)

And if you really didn’t want to define anything on your remote q session then you could send the function definition over too by using the below syntax

%q h: hopen(hostnameport`login)

%q myfunc : { x*x}

%q res: h (myfunc;x)

HTH,

Rebecca

Rebecca Kelly | Kx Technical Evangelist | ML COE US | Kx |  (646) 630-4381 | rebecca@kx.com

""

Hello Rebecca, 

Thank you for your answer. Unfortunately it does not work. For some reason only this syntax work:

%q h(“myfunc : { x*x}”)

%q h(“res:myfunc”)

%q h(“res”)

an the problem with that is that x should be hard-coded but I want it to be a python variable.

I have a feeling that this res: h (myfunc;x) does not really “send data” to the remote process. Indeed when I type 

%q h(“res”) I do not get 4 

but q.res gives 4.

And in my case the data are located in the remote process.

Thank you