package require tclpython
set a 3
set b 5
# Make a Python system within this process
set py [python::interp new]
# Run some code that doesn't return anything
$py exec {import sample}
# Run some code that does return something; note that we substitute a and b
# *before* sending to Python
set result [$py eval "sample.f2($a,$b)"]
puts "result = $result"
# Dispose of the interpreter now that we're done
python::interp delete $py
使用tclpython,可以执行进程内评估:
在使用求值时,要注意的主要问题是引用传递到Python代码中的复杂值。对于数字来说这是微不足道的,并且需要小心引用字符串。在
看起来您需要启动一个python解释器,读取示例脚本,调用函数,然后打印结果。然后,Tcl可以捕获打印输出:
相关问题 更多 >
编程相关推荐