我有一个用tcl写的工具,我想用Python脚本来使用它。will将调用file2.py,后者将调用file3.tcl中的procedure_a。
File1.tcl
set names(1) Jane
set names(2) Tom
set names(3) Elisabeth
set names(4) Robert
set names(5) Julia
set names(6) Victoria
set output [exec /home/Python-2.7.6/./python /home/usr1/tests/ file2.py [array get names]]file2.py
from Tkinter import Tcl
tcl = Tcl()
tcl.eval('source /home/mbenabu/vtf/procs/Linux/file3.tcl')
tcl.eval('proc1 {%s} ' % [sys.argv[1]])
file3.tcl
proc proc1 (array)
// do something with the array.问:当我从py脚本调用proc1时,在proc1中接收到的“数组”是一个字符串而不是数组,因此从py脚本调用“proc1”失败。
如何将数组发送到proc1?
发布于 2015-02-24 05:21:20
发送数组很棘手-在Tcl中,它们是变量而不是值的集合,这是一个非常重要的区别,因为变量不是一级实体-但您可以发送数组的序列化并重新构造它,这对于传送值很有效。
要序列化数组,请使用返回字典值的array get。您的代码示例已经做到了这一点。相反的操作是array set,它位于被调用的过程内部:
proc proc1 {dictionary} {
array set ary $dictionary
# Now we have a copy of the array and can do what we want to it
puts "ary(1) is $ary(1)"
}如果你在同一个Tcl解释器中运行,你会有其他的选择,比如使用一个共享的全局数组。或者你可以使用像Tequila这样的东西来创建一个共享数组服务,尽管如果你这样做会有很多注意事项(我个人不会这么做)。
https://stackoverflow.com/questions/28676374
复制相似问题