Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69594 > unrolled thread
| Started by | Walter Hurry <walterhurry@gmail.com> |
|---|---|
| First post | 2014-04-03 17:06 +0000 |
| Last post | 2014-04-03 23:57 +0100 |
| Articles | 9 — 7 participants |
Back to article view | Back to comp.lang.python
Two Questions about Python on Windows Walter Hurry <walterhurry@gmail.com> - 2014-04-03 17:06 +0000
Re: Two Questions about Python on Windows maxerickson@gmail.com - 2014-04-03 10:31 -0700
Re: Two Questions about Python on Windows Tim Roberts <timr@probo.com> - 2014-04-05 14:57 -0700
Re: Two Questions about Python on Windows Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-03 11:54 -0600
Re: Two Questions about Python on Windows Terry Reedy <tjreedy@udel.edu> - 2014-04-03 14:34 -0400
Re: Two Questions about Python on Windows Ethan Furman <ethan@stoneleaf.us> - 2014-04-03 11:00 -0700
Re: Two Questions about Python on Windows Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-04-03 21:15 +0100
Re: Two Questions about Python on Windows Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-03 16:41 -0600
Re: Two Questions about Python on Windows Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-04-03 23:57 +0100
| From | Walter Hurry <walterhurry@gmail.com> |
|---|---|
| Date | 2014-04-03 17:06 +0000 |
| Subject | Two Questions about Python on Windows |
| Message-ID | <lhk4el$91k$1@news.albasani.net> |
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?
[toc] | [next] | [standalone]
| From | maxerickson@gmail.com |
|---|---|
| Date | 2014-04-03 10:31 -0700 |
| Message-ID | <e79cad43-2eb0-4e22-9bca-c7f0e2319caa@googlegroups.com> |
| In reply to | #69594 |
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
[toc] | [prev] | [next] | [standalone]
| From | Tim Roberts <timr@probo.com> |
|---|---|
| Date | 2014-04-05 14:57 -0700 |
| Message-ID | <stu0k9910gcm9jq84ilcovd0vbif7tndef@4ax.com> |
| In reply to | #69596 |
maxerickson@gmail.com wrote:
>
>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).
Let me clarify that just a bit.
There are several ways to run Python scripts from a Windows command line.
You can invoke the interpreter specifically by name:
C:\Apps\Python27\python xxx.py
C:\Apps\Python27\python xxx.pyw
Or, if the Python directory is in your path:
python xxx.py
python xxx.pyw
If the .py and .pyw extension are registered using assoc and ftype (which
the Windows installer does), then you can invoke them by file name:
xxx.py
xxx.pyw
If you add those extensions to PATHEXT, then you do not even need to
provide the extension, so they will look just like any other automatically
executable program:
xxx
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2014-04-03 11:54 -0600 |
| Message-ID | <mailman.8846.1396547693.18130.python-list@python.org> |
| In reply to | #69594 |
[Multipart message — attachments visible in raw view] — view raw
On Apr 3, 2014 11:12 AM, "Walter Hurry" <walterhurry@gmail.com> 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? Yes. The only distinction between .py and .pyw is that the Python installer associates the former with Python.exe and the latter with Pythonw.exe. Pythonw runs the script without creating a console window for stdin/stdout. > 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. I don't believe this is exactly correct. Python will only use a .pyc automatically for imported modules. For a file specified on the command line, Python won't try to second-guess the user as to which file they want. The file could have a .php extension, and Python will happily run it if the contents are valid Python code. > Question 2: Does it work the same way on Windows, and does this apply both to foo.py and foo.pyw? Yes.
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2014-04-03 14:34 -0400 |
| Message-ID | <mailman.8850.1396550097.18130.python-list@python.org> |
| In reply to | #69594 |
On 4/3/2014 1:06 PM, 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. If he edits the file with Idle (see Start menu Python directory, F5 runs the file and uses the Idle shell for input and output. When the program finishes, one can interactively examine objects and call functions. F5 Run is like running a program from a console with -I. -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| Date | 2014-04-03 11:00 -0700 |
| Message-ID | <mailman.8854.1396554748.18130.python-list@python.org> |
| In reply to | #69594 |
On 04/03/2014 10:54 AM, Ian Kelly wrote: > On Apr 3, 2014 11:12 AM, "Walter Hurry" wrote: >> >> 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. > > I don't believe this is exactly correct. Python will only use a .pyc automatically for imported modules. For a file > specified on the command line, Python won't try to second-guess the user as to which file they want. The file could > have a .php extension, and Python will happily run it if the contents are valid Python code. Right. When specifying the file as a command-line argument to python, you have it include the extension, and that is exactly the file that python executes. Also, using this method, a .pyc file is not created. Only imported files may have a .py[co] file automatically created for corresponding .py file. -- ~Ethan~
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-04-03 21:15 +0100 |
| Message-ID | <mailman.8855.1396556154.18130.python-list@python.org> |
| In reply to | #69594 |
On 03/04/2014 18:54, Ian Kelly wrote: > > On Apr 3, 2014 11:12 AM, "Walter Hurry" <walterhurry@gmail.com > <mailto:walterhurry@gmail.com>> 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? > > Yes. The only distinction between .py and .pyw is that the Python > installer associates the former with Python.exe and the latter with > Pythonw.exe. Pythonw runs the script without creating a console window > for stdin/stdout. > Not with more modern versions of Python. c:\Users\Mark>assoc .py .py=Python.File c:\Users\Mark>ftype Python.File Python.File="C:\Windows\py.exe" "%1" %* c:\Users\Mark>assoc .pyw .pyw=Python.NoConFile c:\Users\Mark>ftype Python.NoConFile Python.NoConFile="C:\Windows\pyw.exe" "%1" %* -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2014-04-03 16:41 -0600 |
| Message-ID | <mailman.8862.1396564935.18130.python-list@python.org> |
| In reply to | #69594 |
On Thu, Apr 3, 2014 at 2:15 PM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote: > On 03/04/2014 18:54, Ian Kelly wrote: >> >> >> On Apr 3, 2014 11:12 AM, "Walter Hurry" <walterhurry@gmail.com >> <mailto:walterhurry@gmail.com>> 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? >> >> Yes. The only distinction between .py and .pyw is that the Python >> installer associates the former with Python.exe and the latter with >> Pythonw.exe. Pythonw runs the script without creating a console window >> for stdin/stdout. >> > > Not with more modern versions of Python. > > c:\Users\Mark>assoc .py > .py=Python.File > > c:\Users\Mark>ftype Python.File > Python.File="C:\Windows\py.exe" "%1" %* Which ultimately calls some version of python.exe. > c:\Users\Mark>assoc .pyw > .pyw=Python.NoConFile > > c:\Users\Mark>ftype Python.NoConFile > Python.NoConFile="C:\Windows\pyw.exe" "%1" %* Which ultimately calls some version of pythonw.exe. I elided that detail because it wasn't relevant to the question at hand.
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-04-03 23:57 +0100 |
| Message-ID | <mailman.8865.1396565869.18130.python-list@python.org> |
| In reply to | #69594 |
On 03/04/2014 23:41, Ian Kelly wrote: > On Thu, Apr 3, 2014 at 2:15 PM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote: >> On 03/04/2014 18:54, Ian Kelly wrote: >>> >>> >>> On Apr 3, 2014 11:12 AM, "Walter Hurry" <walterhurry@gmail.com >>> <mailto:walterhurry@gmail.com>> 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? >>> >>> Yes. The only distinction between .py and .pyw is that the Python >>> installer associates the former with Python.exe and the latter with >>> Pythonw.exe. Pythonw runs the script without creating a console window >>> for stdin/stdout. >>> >> >> Not with more modern versions of Python. >> >> c:\Users\Mark>assoc .py >> .py=Python.File >> >> c:\Users\Mark>ftype Python.File >> Python.File="C:\Windows\py.exe" "%1" %* > > Which ultimately calls some version of python.exe. > >> c:\Users\Mark>assoc .pyw >> .pyw=Python.NoConFile >> >> c:\Users\Mark>ftype Python.NoConFile >> Python.NoConFile="C:\Windows\pyw.exe" "%1" %* > > Which ultimately calls some version of pythonw.exe. > > I elided that detail because it wasn't relevant to the question at hand. > Yes, I regretted how badly I worded the above the second I hit the send button. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web