How to embed Tcl in Python?

Chi-Feng Wu cfwu at larc.ee.nthu.edu.tw
Sun Dec 9 03:37:53 EST 2001


Hi everyone,

Python is my favorite language but I still have difficulty to use
it at work.  Here almost everyone else is using Tcl as the
scripting interface to their tools.

Recently I've bee playing with Tkinter and Tix and realize that
root = Tkinter.Tk()
root.withdraw()
tcli = root.tk.eval
tcli('puts "Hello Tcl!"')

then tcli is effectively a Tcl interpreter!

Here is the question:
How can I use this tcli (or something else) to provide a
scripting interface to my python program? For  example, assume we
have a function 'enc' written in python, and the usage in python
may look like this:

from MyCodec import enc
output_str = enc(input_str, coding_alg)

If I want to use Tcl as the interface to users, then the
following Tcl command have to do the same thing in "Tcl Mode":

set output_str [enc -input $input_str -alg $coding_alg]

But how to 'export' a Python function to the Tcl (interpreter)?

Regards,
CF
--
Chi-Feng Wu, Ph.D Student    |  Tel: +886 3 5715131 ext. 4154
Dept. Electrical Engineering |  Fax: +886 3 5731149
Tsing Hua University         |  E-mail: cfwu at larc.ee.nthu.edu.tw
Hsinchu, Taiwan              |  http://larc.ee.nthu.edu.tw/~cfwu



More information about the Python-list mailing list