如何在 kdb+ 中将 table 的名称作为字符串获取
How can I get the name of a table as a string in kdb+
例如,如果 table 是 tbl_trade_jan17
,我怎样才能得到一个字符串变量 "tbl_trade_jan17"
?恐怕我可能在这里遗漏了一些非常明显的东西!
动机不是使用 get
或 eval
或从其名称调用 table - 功能。
这个想法是将 table 保存在硬盘上,文件名与 table 的名称相同。也参考相关的 tables。例如 trd_jan17
也可能有一个 quote_jan17
table 和一个 sym_jan17
table 关联。所以如果我能得到名字 tbl_trade_jan17
,我就可以通过字符串操作得到关联的 table 的名字。
使用string
函数
q) string `tbl_trade_jan17
"tbl_trade_jan17"
编辑:上述问题已更改
如果我错了请纠正我,但您似乎希望能够从字符串 "tbl_trade_jan17" 中调用您的 table?
在这种情况下,get 和 value 可为此目的互换。
q)tbl_trade_jan17:([]c:1 2 3;c2:1 2 3)
q)type tbl_trade_jan17 / tbl_trade_jan17 is a table (type 98h)
98h
q)/ to use the string as a variable to retrieve the table:
q)get "tbl_trade_jan17"
c c2
----
1 1
2 2
3 3
q)value "tbl_trade_jan17"
c c2
----
1 1
2 2
3 3
idea is to save the table on the hard disk with the same filename as the name of the table.
要获取已定义表的列表,请使用 tables
例如
tables`. //for the root name-space
您可以使用 like
进行过滤
例如
t:tables`.
t:t where t like "pattern_*"
然后用save
保存
save each hsym t //careful
例如,如果 table 是 tbl_trade_jan17
,我怎样才能得到一个字符串变量 "tbl_trade_jan17"
?恐怕我可能在这里遗漏了一些非常明显的东西!
动机不是使用 get
或 eval
或从其名称调用 table - 功能。
这个想法是将 table 保存在硬盘上,文件名与 table 的名称相同。也参考相关的 tables。例如 trd_jan17
也可能有一个 quote_jan17
table 和一个 sym_jan17
table 关联。所以如果我能得到名字 tbl_trade_jan17
,我就可以通过字符串操作得到关联的 table 的名字。
使用string
函数
q) string `tbl_trade_jan17
"tbl_trade_jan17"
编辑:上述问题已更改
如果我错了请纠正我,但您似乎希望能够从字符串 "tbl_trade_jan17" 中调用您的 table? 在这种情况下,get 和 value 可为此目的互换。
q)tbl_trade_jan17:([]c:1 2 3;c2:1 2 3)
q)type tbl_trade_jan17 / tbl_trade_jan17 is a table (type 98h)
98h
q)/ to use the string as a variable to retrieve the table:
q)get "tbl_trade_jan17"
c c2
----
1 1
2 2
3 3
q)value "tbl_trade_jan17"
c c2
----
1 1
2 2
3 3
idea is to save the table on the hard disk with the same filename as the name of the table.
要获取已定义表的列表,请使用 tables
例如
tables`. //for the root name-space
您可以使用 like
例如
t:tables`.
t:t where t like "pattern_*"
然后用save
save each hsym t //careful