crossing boundaries into Tcl
David Gravereaux
davygrvy at pobox.com
Thu May 31 18:27:47 EDT 2001
Hi All,
Being a Tcl-Head, python is new to me.
I just got tclpython from ->
http://jfontain.free.fr/tclpython.htm
http://jfontain.free.fr/tclpython-2.0.1.tar.gz
After a few edits to work on windows, I tried it, but no return value is sent
back to Tcl:
D:\itcl_exp>tclsh84
% load tclpython20.dll
% set i [python::interp new]
python0
% $i eval {import sys ; sys.version}
% $i eval {sys.version}
% $i eval {_}
python0: Traceback (most recent call last):
File "<string>", line 1, in ?
NameError: name '_' is not defined
%
Yet from the python shell:
D:\Python21>python
ActivePython 2.1, build 210 ActiveState)
based on Python 2.1 (#15, Apr 23 2001, 18:00:35) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.version
'2.1 (#15, Apr 23 2001, 18:00:35) [MSC 32 bit (Intel)]'
>>> _
'2.1 (#15, Apr 23 2001, 18:00:35) [MSC 32 bit (Intel)]'
>>>
In the source code for tclpython, is a note that states a small patch is needed
to python to enable return values:
/* in ceval.c, eval_code2():
case POP_TOP:
v = POP();
// (this line added) store result in _ global variable
PyDict_SetItemString(f->f_globals, "_", v);
Py_DECREF(v);
continue;
*/
I would not like to patch python to run it from Tcl, if at all possible. How
can I grab the result of an operation called by PyRun_String()? Is it lost
forever in the POP when v decremented? I really have no clue what I'm doing :)
TIA,
--
David Gravereaux <davygrvy at pobox.com>
More information about the Python-list
mailing list