Compiler directives in the source

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Feb 6 09:35:33 EST 2003


Peter Hansen <peter at engcorp.com> wrote in 
news:3E4263F2.63C07B74 at engcorp.com:

> Very helpful for simple utilities, although so far I haven't found
> any way to avoid hardcoding the path to the batch file (even when
> it's in the PATH) in front of the %0.bat for real uses...  DOS sucks.

This works on win2k, and possibly also on NT 4 SP something:
---- begin test.cmd ---
@python -x "%~f0" %* && goto :eof

# Python code goes here

import sys
print "Args are"," ".join(sys.argv)
--- end test.cmd ---

The %~f0 expands %0 to a fully qualified pathname. Type 'HELP CALL' for the 
various options in argument substitution (and HELP SET for another 
unrelated set of substitution options). Batch files suck.

A better way to do this for many purposes is to add .py to the PATHEXT 
evironment variable, then you don't need batch wrappers.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list