Dictionary 如何在tcl中将变量作为关键路径传递给dict get?

Dictionary 如何在tcl中将变量作为关键路径传递给dict get?,dictionary,tcl,Dictionary,Tcl,我有以下“多维”词典 dict set atm_prms bb N [dict create volume 13.3 radius 1.65 vdw_nrg -1.0906 ] dict set atm_prms bb CA [dict create volume 9.4 radius 1.8 vdw_nrg -0.7708 ] dict set atm_prms bb C [dict create volume 9.82 radius 1.4 vdw_nrg -0.8052 ] dict se

我有以下“多维”词典

dict set atm_prms bb N [dict create volume 13.3 radius 1.65 vdw_nrg -1.0906 ]
dict set atm_prms bb CA [dict create volume 9.4 radius 1.8 vdw_nrg -0.7708 ]
dict set atm_prms bb C [dict create volume 9.82 radius 1.4 vdw_nrg -0.8052 ]
dict set atm_prms bb O [dict create volume 8.2 radius 1.4 vdw_nrg -0.6724 ]
dict set atm_prms bb OXT [dict create volume 8.2 radius 1.4 vdw_nrg -0.6724 ]
dict set atm_prms ALA CB [dict create volume 16.15 radius 1.9 vdw_nrg -1.3243 ]
dict set atm_prms ARG CB [dict create volume 12.77 radius 1.9 vdw_nrg -1.0471 ]
dict set atm_prms ARG CG [dict create volume 12.77 radius 1.9 vdw_nrg -1.0471 ]
dict set atm_prms ARG CD [dict create volume 12.77 radius 1.9 vdw_nrg -1.0471 ]
dict set atm_prms ARG NE [dict create volume 9 radius 1.65 vdw_nrg -0.738 ]
dict set atm_prms ARG CZ [dict create volume 6.95 radius 1.4 vdw_nrg -0.5699 ]
dict set atm_prms ARG NH1 [dict create volume 9 radius 1.65 vdw_nrg -0.738 ]
dict set atm_prms ARG NH2 [dict create volume 9 radius 1.65 vdw_nrg -0.738 ]
dict set atm_prms ASN CB [dict create volume 12.77 radius 1.9 vdw_nrg -1.0471 ]
dict set atm_prms ASN CG [dict create volume 9.82 radius 1.9 vdw_nrg -0.8052 ]
dict set atm_prms ASN OD1 [dict create volume 8.17 radius 1.4 vdw_nrg -0.6699 ]
dict set atm_prms ASN ND2 [dict create volume 13.25 radius 1.65 vdw_nrg -1.0865 ]
如何使用存储在变量中的键路径来检索值

例如,这是有效的:

> puts [dict get $atm_prms ALA CB volume]
16.15
但这失败了:

> set my_path {ALA CB volume}
> puts [dict get $atm_prms $my_path]
key "ALA CB volume" not known in dictionary
如何正确使用存储在变量中的键路径?

因为
将“ALA CB volume”
替换为
dict get
命令中的单个单词。您需要告诉Tcl,您希望将该列表扩展为单独的单词:

% puts [dict get $atm_prms $my_path]
key "ALA CB volume" not known in dictionary
% puts [dict get $atm_prms {*}$my_path]
16.15

请参见

中的规则5,非常好!这种语言需要一些时间来适应。。。Lo.true,但是考虑到整个语言只有12个语法规则。尽情享受这些,你就会变得金灿灿。这正是你需要习惯的部分-P