This package allows the execution of Python code from a Tcl interpreter, as in:
package require tclpython set interpreter [python::interp new] $interpreter eval {print("Hello World")} python::interp delete $interpreter
It works by creating an embedded Python interpreter and sending it strings to evaluate. Modules can be loaded in the Python interpreter as if it were the real python program.
As expected, eval returns whatever the Python interpreter would print in interactive mode and reports an error at the Tcl level when the Python interpreter itself fails in executing the code string.
As in Python interactive mode, the result of the last valid expression is assigned to the variable '_'.
For example:
$interpreter eval 3/2.0 puts [$interpreter eval _]prints:
1.5
You can actually create several Python interpreters, if the tclpython package was linked against a Python library compiled with threads support, otherwise only 1 Python interpreter can exist at a time.
Notes:
Send your comments, complaints, ... to jfontain@free.fr.
My homepage is at http://jfontain.free.fr/.