Converting .py files to batch files.

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Sep 16 00:56:47 EDT 2008


En Mon, 15 Sep 2008 20:36:05 -0300, Michael Palmer <m_palmer45 at yahoo.ca>  
escribió:
>> aditya shukla escribió:
>>
>> > How can we convert .py files to batch files? is there any library for  
>> this?
>
> I assume you are on Windows? Let's assume you have a file stuff.py
> that reads:
>
> import os
> print os.listdir('.') # list current directory, good enough for
> testing...
>
> Then, insert the following line at the top:
>
> @setlocal enableextensions & python -x %~f0 %* & goto :EOF
>
> Now save this file as stuff.cmd somewhere along your PATH. Now calling
> 'stuff' should execute your file.

Cool! I'd enclose the first argument in quotes "%~f0" - in case the path  
contains any whitespace.

-- 
Gabriel Genellina




More information about the Python-list mailing list