Converting .py files to batch files.

Michael Palmer m_palmer45 at
Tue Sep 16 01:36:05 CEST 2008

On Sep 15, 3:04 pm, Matias Surdi <matiassu... at> wrote:
> aditya shukla escribió:
> > How can we convert .py files to batch files? is there any library for this?
> > Aditya
> > ------------------------------------------------------------------------
> > --
> >
> Maybe py2exe can help you.

I assume you are on Windows? Let's assume you have a file
that reads:

import os
print os.listdir('.') # list current directory, good enough for

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.
On Linux, you would instead insert the shebang line that points to
your python interpreter, such as


at the top and also set the executable bit, but I suppose if you use
Linux at all you know that.

More information about the Python-list mailing list