简体   繁体   English

将Python脚本中的变量传递给tcl shell

[英]Passing a Variable from Python script to tcl shell

I am new to this forum, so I apologize beforehand for any mistakes. 我是这个论坛的新手,所以我事先为任何错误道歉。 I am trying to pass a variable from my python code to tcl script. 我试图将我的python代码中的变量传递给tcl脚本。 The way I am doing this is: 我这样做的方式是:

import os
import Tkinter
from Tkinter import *

def set_impairments(port,delay):

    port=int(port)
    delay=int(delay)
    tcl = Tcl()
    tcl.eval("""
    proc my_proc {in_port,in_delay} {

    puts in_port
    puts in_delay
    }
    """)
    print port
    print delay

    tcl.eval('my_proc port,delay')

set_impairments(0,25000)

The output of this code is: 此代码的输出是:

0

25000

in_port

in_delay

How to assign in_port to 0 and in_delay to 25000? 如何将in_port指定为0,将in_delay指定为25000? I am not able to understand why it is not able to pass the value of the variable. 我无法理解为什么它无法传递变量的值。

Tcl doesn't use commas to separate arguments, it uses whitespace. Tcl不使用逗号分隔参数,它使用空格。 Also, you need a $ to reference the value of the variable. 此外,您需要$来引用变量的值。 Do this: 做这个:

proc my_proc {in_port in_delay} {
    puts $in_port
    puts $in_delay
}

I'm not really a python guy, but you probably want 我不是一个蟒蛇人,但你可能想要

tcl.eval('my_proc {0} {1}'.format(port,delay))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM