How to make python scripts .py executable, not bring up editor

norseman norseman at hughes.net
Mon Jul 7 21:00:16 EDT 2008


korean_dave wrote:
>>From command Prompt, i type in a script,  "tryme.py".
> 
> This, instead, brings up PythonWin editor and Interactive Window.
> 
> Path variable is "C:\Python24". (I need Python 2.4 installed, not 2.5)
> 
> How do I make it so that the script runs?
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
======================================
I get tired of Microsoft jerking me around too.  Rather than spend hours 
trying to undo somebody's reorganizing my system preferences I just 
ignore them completely.

py tryme         is how I do it.

py.bat is a file placed in a directory listed in PATH in autoexec.bat. 
Edit autoexec.bat to include directory you put it in and reboot system 
or it won't find it.  something like:  PATH=.;c:\py-stuff;[anything 
already listed]    Don't forget the semicolons.

The . (period) up front means look here first. here being where ever you 
are when you issued the command. (The pRESENT wORKING dIRECTORY :-) The 
c:\py-stuff (fix to suit yourself and make sure it exists) is where you 
can put your efforts to be called at your leisure. Your .py files you 
write and use. Even the py.bat can go there.

(Short note: Microsoft usually does look in pwd first. But good form 
dictates being specific.)

contents of py.bat:
========================
rem     name: py.bat
@echo off
c:\Python24\python %f.py                    make it fit your path
rem     end of file
========================

This way - you get what you expect, when you expect it, & nothing else.
Yeah - dumb, but it works!  I have one similar for each of my compilers.
They contain the whole command line switches stuff as well as things 
like remove old stuff before trying to over write with new since MS can 
be temperamental about that.

Easiest way in the world to give it the finger and make it behave.

Steve
norseman at hughes.ney



More information about the Python-list mailing list