简体   繁体   中英

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. 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? 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. 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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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