Posts: 1,298
Threads: 38
Joined: Sep 2016
(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
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
Posts: 1,298
Threads: 38
Joined: Sep 2016
(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)
1 2 3 4 5 6 7 8 9 10 |
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
Posts: 1,298
Threads: 38
Joined: Sep 2016
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