我正在尝试将Tcl键列表传递给函数,当我访问函数中的变量时,它的类型不是键列表。用于获取密钥列表的包是TclX。
示例代码:
keylset x port1.port "1/1"
keylset x port1.stream "1"
# keylkeys x works at this point
keylset y port1.port "1/1"
keylset y port2.port "1/2"
keylset y port1.stream "1"
# keylkeys y works at this point
# Following call returns error: the error is keyed list entry must be a valid, 2 element list, got "port1"
proc_name $x
# Following call is successful
proc_name $y
# procedure is part of a package and the package is sourced at the start of the script
proc proc_name {x} {
# puts x for one port input -> port1 {{port 1/1} {stream 1}}
# puts y for one port input -> { {port1 {{port 1/1} {stream 1}}} {port2 {port 1/1}} }
puts [keylkeys x]
}
我不确定为什么传递给程序
时无法识别密钥列表答案 0 :(得分:0)
我没有tcl与tclx进行测试,但是你可能需要将列表变量 name 传递给proc然后在里面使用upvar
。试试这个:
keylset x ...
keylset y ...
proc_name x ;# just the varname
proc_name y ;# just the varname
proc proc_name {varname} {
upvar 1 $varname keyedlist
puts [keylkeys keyedlist]
}
答案 1 :(得分:0)
这就解决了我的问题,是因为其他人今后也遇到了同样的问题(信誉来自我的一位同事):
由于程序中的打印显示缺少一组""
,我在函数调用之前添加了一组额外的# please refer to the code in the question section, I am just adding the changed snippet here
proc_name \"$x\" ;# solved the problem inside the procedure
。
from selenium.webdriver.support.ui import Select
select = Select(driver.find_element_by_id('matrix-element-666'))
select.select_by_value('unisexur').click()