Is there a way to get the location of the current running file in q in a similar fashion then Python's __file__
.
Getting the location of the current file in q (kdb)
http://code.kx.com/q/ref/dotz/#zf-file
You can use .z.f
for this, it contains the name of the file loaded on command line. Doesn't work for files loaded with \l
though
jonny@grizzly ~ $ echo 'show .z.f' > a.q
jonny@grizzly ~ $ q a.q
KDB+ 3.5 2017.10.11 Copyright (C) 1993-2017 Kx Systems
l32/ 2()core 1945MB jonny grizzly 127.0.1.1 NONEXPIRE
`a.q
q)\\
jonny@grizzly ~ $ q
KDB+ 3.5 2017.10.11 Copyright (C) 1993-2017 Kx Systems
l32/ 2()core 1945MB jonny grizzly 127.0.1.1 NONEXPIRE
q)\l a.q
`
q)\\
If you need to find the location of a function loaded in a script with \l
you can get this info from value .z.s
in recent versions of kdb:
jonny@grizzly ~ $ echo 'b:{show value[.z.s]8}' > b.q
jonny@grizzly ~ $ echo 'c:{show value[.z.s]8}' > c.q
jonny@grizzly ~ $ q
KDB+ 3.5 2017.10.11 Copyright (C) 1993-2017 Kx Systems
l32/ 2()core 1945MB jonny grizzly 127.0.1.1 NONEXPIRE
q)\l b.q
q)\l c.q
q)b[]
"/home/jonny/b.q"
q)c[]
"/home/jonny/c.q"
Note that this behaviour is different in older versions of kdb. For reference, there is additional information available from value .z.s
:
jonny@grizzly ~ $ echo 'd:{show value[.z.s]}' > d.q
jonny@grizzly ~ $ q
KDB+ 3.5 2017.10.11 Copyright (C) 1993-2017 Kx Systems
l32/ 2()core 1945MB jonny grizzly 127.0.1.1 NONEXPIRE
q)\l d.q
q)d[]
0x7733a0520002
,`x
`symbol$()
,`
k){1 .Q.s x;}
12 6 1 1
"..d"
"/home/jonny/d.q"
1
"{show value[.z.s]}"
See http://code.kx.com/q/ref/metadata/#value for more details
I am very sorry for my late response. I deeply hate q but I am force to work with it. Nevertheless, this answer is, far ahead, the best answer I got of any q related questions. Thousand thanks. –
Hargrove
© 2022 - 2024 — McMap. All rights reserved.