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!
-
3The answers to this question might be helpful. stackoverflow.com/questions/1004434/…Stephen Terry– Stephen Terry2011年09月09日 14:19:41 +00:00Commented 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.mcfly– mcfly2011年09月09日 15:34:44 +00:00Commented 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.htmlkostix– kostix2011年09月09日 16:38:04 +00:00Commented Sep 9, 2011 at 16:38
-
1Though 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.SingleNegationElimination– SingleNegationElimination2011年09月09日 18:15:59 +00:00Commented 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?mcfly– mcfly2011年09月28日 14:41:59 +00:00Commented Sep 28, 2011 at 14:41
2 Answers 2
Try this
import Tkinter
r=Tkinter.Tcl()
r.eval('source DIS.tcl')
Bryan Oakley
389k53 gold badges584 silver badges741 bronze badges
answered Jan 6, 2015 at 12:34
fahad
3,1993 gold badges21 silver badges20 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Tcl is very sensitive to whitespace (much like Bourne shell). You probably want source DIS.tcl instead of source{DIS.tcl}
answered Sep 9, 2011 at 15:53
glenn jackman
249k42 gold badges233 silver badges363 bronze badges
2 Comments
Donal Fellows
source {DIS.tcl} would also work, so long as the space is there.SingleNegationElimination
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.lang-py