How to? return values from @python

May 31, 2008
What techniques are available to return values from %@python[] to TCC ?
I have been exploring some straightforward ways, but I can't see how to get something out of @python except for console output. Note that I am not using the supported ActivePython but another distribution, so my issue could be all there. Anyways, this is what I tried:
  1. Capture standard output: set x=%@python[print 1+1] >out
    This sets x=0 (python's exit code?), creates an empty out file and prints 2 to the console.
  2. Set a TCC variable from python: how can I do that?
    Incidentally I discovered that the persistent python interpreter gets its own frozen environment block, so setting environment variables, like $PATH, from python is pointless because changes aren't reflected in TCC's environment block.
  3. Write to a file from python. Here is a working example, but I would like to find a memory based solution as well, like #2.
set tmpf=%@unique["%[TEMP]"]
echo>nul %@python[with open(r'%[tmpf]','w') as tmpf: print >>tmpf, 1+1]
type "%[tmpf]"
del "%[tmpf]"
I can't speak for the Python support Stefano, but the equivalent @REXX simply allows you to return a numeric value valid as an exit code (REXX has both EXIT and RETURN 'statements' that can be used to achieve that). Any attempt to return a value that cannot be interpreted as a number (and this might differ for python, REXX has no data typing so all data are effectively strings) causes the TCC instance to crash.
May 31, 2008
Thanks Steve. I read in an older thread of this forum that performing an exit(n) in python closes the TCC session as well because the python interpreter is persistent.
Similar threads
Thread starter Title Forum Replies Date
A WAD function return values with parentheses prevent evaluation of additional functions Support 31
vefatica Is EOF an implied RETURN? Support 3
Joe Caverly Why does TCCRT return VIEW as an internal command? Support 6
D Can the argument to RETURN be a function expansion? Support 3
A Inconsistent return code for TCC scripts Support 4
J How to? Speedup of gosub/return Support 8
vefatica Can a subroutine return a 64-bit integer? Support 4
S Return of FTP copy bug in 16.02.48 Support 12
M How to? Get the return code from an external program... Support 8
A How to? return to completion mask after auto-completion Support 14
ehab aboudaya How to? 2 GUI questions and return HWND using TakeCommandIPC Support 3
M echo %@index[1234,.,-1] return -21 in new version Support 3
Jay Sage Function to Return Selected Text Support 2
rconn Do NOT request return receipt! Support 7
rconn No return receipt!! Support 10
Joe Caverly PSHELL and @PSHELL errorlevel values Support 4
rps Fixed @filesize[...,a] space allocated values incorrect Support 2
Charles Dye REGDIR reports QWORD values incorrectly Support 3
T read snmp values Support 4
T How to? Show the values of batch variables on the TCC screen Support 21
S WAD Incorrect _do_loop values Support 18
Charles Dye Fixed TYPE /X reports FF for all values >= 80h Support 6
vefatica Debugger: popup _VARIABLE values Support 1
D Force For to treat set of values as text, not files Support 3
B %ProgramFiles(x86)% returns different values in TCC and CMD Support 3
Joe Caverly PYTHON from Microsoft Windows Store Support 2
Alpengreis UTF-8 problem in TCC related to Python Support 7
Alpengreis Python support for 3.8.3 in TCC v26.x? Support 2
N Python 3.8.2 Support in 26? Support 3
fpefpe Python dll error Support 3
MickeyF Why doesn't my python program get executed without specifying its path? Support 2
J Error running Python at command line Support 9
fpefpe Documentation Python Examples Support 14
fpefpe Documentation Python support Support 11
jbanaszczyk Non ActiveState Python/Perl Support 4
J Python: TCC command line parsing removes '=' equal sign characters Support 4
fpefpe WAD Python support does not process command line Support 14
fpefpe How to? Path(s) for Python Support 0
fpefpe Documentation Python Support 5
lassevk exit(1) in a python script exits console, by design or bug? Support 1
p.f.moore TCMD v10 - Python support - use version 2.6? Support 2

Similar threads