Two Questions about Python on Windows

maxerickson at gmail.com maxerickson at gmail.com
Thu Apr 3 13:31:55 EDT 2014


On Thursday, April 3, 2014 1:06:29 PM UTC-4, Walter Hurry wrote:
> Normally my Python development is done on FreeBSD and Linux. I know that on *ix I simply have to make foo.py executable (the shebang line is present, of course) to make it runnable.
> 
> For my son's school assignment, I have to help him with Python for Windows.
> 
> As I understand it, on Windows a .py file is not executable, so I need to run 'python foo py', or use a .pyw file.
> 
> Question 1: Do I make a .pyw file simply by copying or renaming foo.py to foo.pyw?
> 
> Secondly, on *ix, if there's an up-to-date .pyc in the right place and I run foo.py, Python will automagically use foo.pyc.
>  
> Question 2: Does it work the same way on Windows, and does this apply both to >foo.py and foo.pyw?

The compile caching is more or less the same. It works transparently.

If you are working in a cmd shell, it doesn't matter what extension you use, pyw just allows for associating scripts with an interpreter stub that does not bring up a shell (for a gui or whatever). Console and gui programs are handled separately on Windows and that's how Python makes the option available to scripts.

You can also edit the PATHEXT environment variable to include .py/.pyw, making the python source files executable (as long as the types are properly registered with Windows; if double clicking runs them they should be properly registered).


Max



More information about the Python-list mailing list