calling python procedures from tcl using tclpython

chand chandra.bangalore at gmail.com
Fri Jul 8 06:11:48 CEST 2005


Hi.,

can anyone help me how to provide the info about the python file
procedure in the tcl script which uses tclpython i.e., is there a way
to import that .py file procedure in the tcl script


--BestRegards
--Chandra

Michael Schlenker wrote:
> chand wrote:
> > Hi..
> >
> > I am writing a Gui in TCL and my backend code is python. I want to call
> > python procedure in tcl using tclpyhton. I want to know clearly how
> > this should be implemented.
> >
> > let's say I have procedure test_function(arg1,arg2 ...) defined in
> > test.py.
> > I want to call this procedure in tcl. Let me know how this should be
> > achieved.
> > The doubt basically have is how the tcl code knows in which .py file
> > this procedure is defined.
> >
> > currently I have wriiten this tcl code which is not working
> >
> > package require tclpython
> > set interpreter [python::interp new]
> > $interpreter eval {def test_function(): arg1,arg2} ;
> > python::interp delete $interpreter
> >
> What does not work? You never load your file test.py anywhere inside,
> you just evaluate 'def test_function(): arg1,arg2' so what are you
> expecting to happen?
>
> Your call to '$interpreter eval' lets you call arbitrary python code,
> but you have to provide the python code that loads your function
> definitions etc. I don't know python, but it should be a trivial code.
> 
> Michael




More information about the Python-list mailing list