Python Forum
[split] launch .PY program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] launch .PY program
#1
(Sep-28-2016, 02:12 PM)metulburr Wrote:
Quote:in windows you can double click on a .py file to run it
You should avoid this method. Not only is it windows dependent, but its better to get into the habit of executing code from the terminal/command prompt (especially for a new programmer). Plus what if you have multiple versions of python installed and you want to test different versions with each error check?

When I started as an apprentice, I was told "Learn the trade, not the tricks of the trade."  I suppose that applies to programming as well. Darned if Python doesn't keep adding 'tricks' to the Windows version though :P .

An example is, starting with v3.3, windows now recognizes the shebang line, so now
#! /usr/bin/env python3
works in both Linux and Windows.

Another example is instead of invoking: python script.py, you only need: py script.py, or py -2 script.py, etc. I haven't tried it in Linux to see if this also works.

Darn you Python developers :D
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#2
(Sep-28-2016, 02:55 PM)sparkz_alot Wrote: An example is, starting with v3.3, windows now recognizes the shebang line, so now
Python Code: (Select All)
#! /usr/bin/env python3 

works in both Linux and Windows.

I have never heard of this. How exactly would windows know where to find python as the shebang line path is linux binaries directory?
Recommended Tutorials:
Reply
#3
If .py is associated with python in the file associations, AND the script is executable, then Windows just looks up the file association. It still ignores the shebang as far as I know (that'd be a change to windows, not an update to python).
Reply
#4
(Sep-28-2016, 02:58 PM)metulburr Wrote:
(Sep-28-2016, 02:55 PM)sparkz_alot Wrote: An example is, starting with v3.3, windows now recognizes the shebang line, so now
Python Code: (Select All)
#! /usr/bin/env python3 

works in both Linux and Windows.

I have never heard of this. How exactly would windows know where to find python as the shebang line path is linux binaries directory?

It's here (about halfway down) https://docs.python.org/3/using/windows.html, I took the liberty of using their sample and ran it using python, python2 and python3 in that order (note: I do not have python v2)

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.
C:\>cd python
C:\Python>test.py
hello from Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)]
C:\Python>test.py
Requested Python version (2) is not installed
C:\Python>test.py
hello from Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)]
C:\Python>
pretty cool :cool:
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#5
Thanks for splitting this from the original thread, was wondering if it could be done :)
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  launch processes from threads Skaperen 9 720 Feb-21-2024, 01:16 AM
Last Post: Skaperen
  [split] the best python teaching program for an 8 year kid? ThomasMoore 2 2,364 Apr-16-2019, 09:12 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020