سؤال

Is there a way to get string representation of k object, similar (better identical) to that printed to q console?

q)([]a:`a`b`c;b:"abc";c:1 2 3)
a b c
-----
a a 1
b b 2
c c 3
q)
هل كانت مفيدة؟

المحلول

.Q.s is used to format something for console printing, can use this to get the q console string.

q)t:([]a:`a`b`c;b:"abc";c:1 2 3)
q)show .Q.s t
    "a b c\n-----\na a 1\nb b 2\nc c 3\n"
q)t:([]a:`a`b`c;b:"abc";c:1 2 3)
q)show str:.Q.s t
    "a b c\n-----\na a 1\nb b 2\nc c 3\n"
q)-1 str;
    a b c
    -----
    a a 1
    b b 2
    c c 3

.Q.s1 can be used to get the single line version of the string.

q).Q.s1 t
   "+`a`b`c!(`a`b`c;\"abc\";1 2 3)"

نصائح أخرى

There are much better ways to do io with kdb.

With csv you can, for example, store tables:

save `:table.csv

or return tables:

http://host:port/q.csv?table

For more on C/C++ integration, see http://code.kx.com/q/interfaces/using-c-functions/

I did some work on C interface with KDB+. It involves printing and creating KDB+ objects using C.

http://code.kx.com/wsvn/code/contrib/aquaqanalytics/InterfacingKDBtoC/?#ab109deb48fbdcebdc610ae05c54e9ede

It might be a bit different in C++ but it should be a starting point for you?

Hope this helps.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top