Converting .py files to batch files.

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


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

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

#!/usr/bin/python

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