嘿python要解析tcl变量吗?努

2024-10-01 07:37:25 发布

您现在位置:Python中文网/ 问答频道 /正文

所以,我试图让python打印一个包含tcl变量的字符串,以及该变量的结果。我在用核弹,以防对我的代码有影响。在

[set THIS image] 
Ln = "/Test/still/testing/$THIS\_clean_v001"
print(Ln) # this prints exactly the above

G = nuke.tcl('[puts "$THIS"] ') 

print(G)是否返回单词image?在

然后我可以把它分进去。问题是我输入的文本字段是tcl用来在程序中很好地解决它的,但是当我把它发送到process时,它就按字面意思使用$THIS。在


Tags: 字符串代码testimagecleanthistestingtcl
2条回答

有两点需要注意:

  1. Tclputs不返回值。听起来你想要Tcl ^{},确实如此。

  2. 位于http://www.nukepedia.com/reference/Pythonnuke.tcl文档表明:

    tcl(command, arg, arg, ...)

    Run a tcl command. The arguments must be strings and passed to the command. If no arguments are given and the command has whitespace in it then it is instead interpreted as a tcl program (this is depreciated)

与其将其作为完整脚本调用,不如使用未弃用的版本并通过以下方式获得所需的行为:

G = nuke.tcl("set", "THIS")

Whic应该重新输入THIS变量的值。在

您还可以使用TCLsubst命令一次性扩展字符串中的所有TCL变量。在

nuke.tcl('set', 'THIS', 'image')
p = '/Test/still/testing/$THIS\_clean_v001'
print nuke.tcl('subst', p)

其结果将是正确展开的字符串:'/Test/still/testing/image_clean_v001'

subst的文档可以在这里找到:http://www.tcl.tk/man/tcl8.4/TclCmd/subst.htm

相关问题 更多 >