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!

5
  • 3
    The answers to this question might be helpful. stackoverflow.com/questions/1004434/… Commented Sep 9, 2011 at 14:19
  • 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. Commented Sep 9, 2011 at 15:34
  • @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.html Commented Sep 9, 2011 at 16:38
  • 1
    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. Commented Sep 9, 2011 at 18:15
  • 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? Commented Sep 28, 2011 at 14:41

2 Answers 2

9

Try this

import Tkinter
r=Tkinter.Tcl()
r.eval('source DIS.tcl')
Sign up to request clarification or add additional context in comments.

Comments

4

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

2 Comments

source {DIS.tcl} would also work, so long as the space is there.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.