crossing boundaries into Tcl

David Gravereaux davygrvy at pobox.com
Fri Jun 1 18:47:52 EDT 2001


"Pete Shinners" <shredwheat at mediaone.net> wrote:

>
>"David Gravereaux" <davygrvy at pobox.com> wrote
>> % $i eval {_}
>> python0: Traceback (most recent call last):
>>   File "<string>", line 1, in ?
>> NameError: name '_' is not defined
>
>hey david. welcome to python. the problem here is that the magic
>"_" underscore variable is not part of the actual python language,
>it is just a little shortcut the interactive interpreter adds
>to represent the last result.
>
>unfortunately i know not enough about python in tcl to know
>how to handle the situation, good luck

Thanks, I'm trying.  I tried calling PyRun_String() with Py_single_input for the
start token, and it looked like it was working at first, but the result was
printed to stdout rather than returned as the return value.  The PyObject* in
the return always say 'None', which I think means "no errors"...

Is there a start token that can return the value of the last operation?  There
must be somewhere.  The result of an eval is such a central concept to Tcl that
I find it strange that it's missing in other interpreted languages.

Tcl_Interp *interp;

interp = Tcl_CreateInterp();
Tcl_Init(interp);
Tcl_Eval(interp, "pwd");
printf("Your current working directory is %s", interp->result);


What's the same concept when using python embedded?  How do you get the result
of an operation as a char*?
--
David Gravereaux <davygrvy at pobox.com>



More information about the Python-list mailing list