Running TCL code from Python
Asked Answered
P

2

7

I want to be able to run a tcl script out of my python script. Specifically, I want to run a tcl script much like this.

I have some knowledge of python and none of tcl.

I have been trying things like:

import Tkinter
r=Tkinter.Tk()
r.call('source{DIS.tcl})' or r.tk.eval('source{DIS.tcl})'

Any ideas how i would access things out of the tcl script? Thanks!

Presidency answered 9/9, 2011 at 14:2 Comment(5)
The answers to this question might be helpful. #1004934Pheidippides
By "access" i just mean i want the output of the tcl code. I tried the things on that other link, but nothing seems to work. Again, i am fairly new to python and just want to understand how it is that python is executing the TCL script. For instance, i do not understand what "r.call('source{DIS.tcl})" was supposed to do.Presidency
@mcfly, 1) understanding is quite easy with tcl.tk/man/tcl8.5/TclCmd/contents.htm 2) Some level of expertize in the target language is required or else it will bite you in the neck later, so at least skim through the tutorial. You can start right at tcl.tk/man/tcl8.5/tutorial/Tcl1.htmlSpinks
Though badly worded, this is NOT a duplicate of the linked question. The problem with this code is not related to executing tcl in python, as suggested in the prose, but with the TCL syntax in the code. glenn's answer explains and solves that issue.Lunde
I have still not been able to get this working. Can anyone tell me how I would do this exactly for the tcl code that i posted above (in the link). I have UDP packets coming over my network with DIS PDUs embedded. How can i read the entity state PDU information using PYTHON?Presidency
A
4

Tcl is very sensitive to whitespace (much like Bourne shell). You probably want source DIS.tcl instead of source{DIS.tcl}

Adamok answered 9/9, 2011 at 15:53 Comment(2)
source {DIS.tcl} would also work, so long as the space is there.Professed
To clarify, the quoting characters {}'s are completely superfluous in this case; TCL expects a command to be made up of words separated by spaces. DIS.tcl does not contain spaces or other tcl special characters, so it doesn't need to be quoted, but it does have to be separated by spaces from the leading proc name.Lunde
S
9

Try this

import Tkinter
r=Tkinter.Tcl()
r.eval('source DIS.tcl')
Sum answered 6/1, 2015 at 12:34 Comment(0)
A
4

Tcl is very sensitive to whitespace (much like Bourne shell). You probably want source DIS.tcl instead of source{DIS.tcl}

Adamok answered 9/9, 2011 at 15:53 Comment(2)
source {DIS.tcl} would also work, so long as the space is there.Professed
To clarify, the quoting characters {}'s are completely superfluous in this case; TCL expects a command to be made up of words separated by spaces. DIS.tcl does not contain spaces or other tcl special characters, so it doesn't need to be quoted, but it does have to be separated by spaces from the leading proc name.Lunde

© 2022 - 2024 — McMap. All rights reserved.