Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98838 > unrolled thread
| Started by | fl <rxjwg98@gmail.com> |
|---|---|
| First post | 2015-11-14 17:54 -0800 |
| Last post | 2015-11-15 21:54 -0700 |
| Articles | 9 — 7 participants |
Back to article view | Back to comp.lang.python
What meaning is of '#!python'? fl <rxjwg98@gmail.com> - 2015-11-14 17:54 -0800
Re: What meaning is of '#!python'? Chris Angelico <rosuav@gmail.com> - 2015-11-15 12:58 +1100
Re: What meaning is of '#!python'? fl <rxjwg98@gmail.com> - 2015-11-14 18:13 -0800
Re: What meaning is of '#!python'? Chris Angelico <rosuav@gmail.com> - 2015-11-15 13:18 +1100
Re: What meaning is of '#!python'? Rob Hills <rhills@medimorphosis.com.au> - 2015-11-15 11:10 +0800
Re: What meaning is of '#!python'? Zachary Ware <zachary.ware+pylist@gmail.com> - 2015-11-14 20:26 -0600
Re: What meaning is of '#!python'? Michael Torrie <torriem@gmail.com> - 2015-11-14 19:28 -0700
Re: What meaning is of '#!python'? eryksun <eryksun@gmail.com> - 2015-11-14 23:57 -0600
Re: What meaning is of '#!python'? <paul.hermeneutic@gmail.com> - 2015-11-15 21:54 -0700
| From | fl <rxjwg98@gmail.com> |
|---|---|
| Date | 2015-11-14 17:54 -0800 |
| Subject | What meaning is of '#!python'? |
| Message-ID | <ed2472ca-7efb-4676-b49e-356260dd533c@googlegroups.com> |
Hi, I see an example Python code has such a line at the file beginning: #!python Is there some meaning about it? Thanks,
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-11-15 12:58 +1100 |
| Message-ID | <mailman.340.1447552722.16136.python-list@python.org> |
| In reply to | #98838 |
On Sun, Nov 15, 2015 at 12:54 PM, fl <rxjwg98@gmail.com> wrote: > I see an example Python code has such a line at the file beginning: > > #!python > > > Is there some meaning about it? It probably didn't look exactly like that. Please, when you're asking questions, COPY AND PASTE rather than retyping some approximation of what you saw. As it happens, I can tell what you're asking about - it's called a shebang - but I very much doubt that it was exactly what you wrote. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | fl <rxjwg98@gmail.com> |
|---|---|
| Date | 2015-11-14 18:13 -0800 |
| Message-ID | <3aa2f352-ea19-4252-9a09-c884887cf810@googlegroups.com> |
| In reply to | #98839 |
On Saturday, November 14, 2015 at 8:58:57 PM UTC-5, Chris Angelico wrote: > On Sun, Nov 15, 2015 at 12:54 PM, fl <gmail.com> wrote: > > I see an example Python code has such a line at the file beginning: > > > > #!python > > > > > > Is there some meaning about it? > > It probably didn't look exactly like that. Please, when you're asking > questions, COPY AND PASTE rather than retyping some approximation of > what you saw. > > As it happens, I can tell what you're asking about - it's called a > shebang - but I very much doubt that it was exactly what you wrote. > > ChrisA Excuse me. Below is copied from the .py file: #!python from numpy import * from numpy.random import * def resample(weights): n = len(weights) indices = [] Thanks,
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-11-15 13:18 +1100 |
| Message-ID | <mailman.341.1447553914.16136.python-list@python.org> |
| In reply to | #98841 |
On Sun, Nov 15, 2015 at 1:13 PM, fl <rxjwg98@gmail.com> wrote: > Excuse me. Below is copied from the .py file: > > #!python > from numpy import * > from numpy.random import * > Then someone doesn't know how to use a shebang (or is deliberately abusing it), and you can ignore it. It starts with a hash, ergo it's a comment. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Rob Hills <rhills@medimorphosis.com.au> |
|---|---|
| Date | 2015-11-15 11:10 +0800 |
| Message-ID | <mailman.348.1447557067.16136.python-list@python.org> |
| In reply to | #98841 |
On 15/11/15 10:18, Chris Angelico wrote:
> On Sun, Nov 15, 2015 at 1:13 PM, fl <rxjwg98@gmail.com> wrote:
>> Excuse me. Below is copied from the .py file:
>>
>> #!python
>> from numpy import *
>> from numpy.random import *
>>
> Then someone doesn't know how to use a shebang (or is deliberately
> abusing it), and you can ignore it. It starts with a hash, ergo it's a
> comment.
>
> ChrisA
Looks like the author of the script file has tried to create a Python
Shell script. This link describes them in detail:
http://www.dreamsyssoft.com/python-scripting-tutorial/intro-tutorial.php
Not sure whether the example originally quoted would work, I imagine it
might on some 'nix operating systems.
The more common first line is:
#!/usr/bin/env python
If you start a script file with this line and make the file executable,
you can then run the script from the command line without having to
preface it with a reference to your Python executable. Eg:
my-script.py
versus
python my-script.py
HTH,
--
Rob Hills
Waikiki, Western Australia
[toc] | [prev] | [next] | [standalone]
| From | Zachary Ware <zachary.ware+pylist@gmail.com> |
|---|---|
| Date | 2015-11-14 20:26 -0600 |
| Message-ID | <mailman.343.1447554433.16136.python-list@python.org> |
| In reply to | #98838 |
On Sat, Nov 14, 2015 at 7:58 PM, Chris Angelico <rosuav@gmail.com> wrote: > On Sun, Nov 15, 2015 at 12:54 PM, fl <rxjwg98@gmail.com> wrote: >> I see an example Python code has such a line at the file beginning: >> >> #!python >> >> >> Is there some meaning about it? > > It probably didn't look exactly like that. Please, when you're asking > questions, COPY AND PASTE rather than retyping some approximation of > what you saw. "#!python" is a valid shebang for the Python Launcher for Windows. It's also a not-too-terrible placeholder for a Unix shebang meaning "whichever Python you want it to be". The better choice for use with both platforms would be "#!/usr/bin/env python", though. -- Zach
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2015-11-14 19:28 -0700 |
| Message-ID | <mailman.344.1447554505.16136.python-list@python.org> |
| In reply to | #98838 |
On 11/14/2015 06:54 PM, fl wrote: > Hi, > > I see an example Python code has such a line at the file beginning: > > #!python > > > Is there some meaning about it? Supposed to be, yes, but the line you've pasted there wouldn't work on any system I know of. https://en.wikipedia.org/wiki/Shebang_%28Unix%29
[toc] | [prev] | [next] | [standalone]
| From | eryksun <eryksun@gmail.com> |
|---|---|
| Date | 2015-11-14 23:57 -0600 |
| Message-ID | <mailman.349.1447567116.16136.python-list@python.org> |
| In reply to | #98838 |
On Sat, Nov 14, 2015 at 8:26 PM, Zachary Ware <zachary.ware+pylist@gmail.com> wrote: > > "#!python" is a valid shebang for the Python Launcher for Windows. > It's also a not-too-terrible placeholder for a Unix shebang meaning > "whichever Python you want it to be". The better choice for use with > both platforms would be "#!/usr/bin/env python", though. The "/usr/bin/env python" virtual command searches the directories in PATH, trying each file extension from PATHEXT such as "python.COM", "python.EXE", and so on. You can also search for other programs such as "pypy". Note that qualifying "python" (but not other names) as "python2" or "python3.5" makes the launcher use the registry instead of searching PATH. "#!/usr/bin/python" may be better in some cases. This defaults to the latest installed version of 2.x (or 3.x if no 2.x is installed) that's configured in the Windows registry. Or specify "python2" or "python3" to use the latest 2.x or 3.x. These commands can be configured to use a particular major[.minor[-32]] version via the environment variables PY_PYTHON, PY_PYTHON2, and PY_PYTHON3. Or you can configure them instead by setting the "python", "python2" and "python3" keys in the [defaults] section of the configuration file "%LOCALAPPDATA%\py.ini". Note that the environment variable overrides the corresponding py.ini key. When portability isn't a concern you can use a Windows path in the shebang such as "#!C:\pypy40\pypy.exe". https://docs.python.org/3/using/windows.html#shebang-lines
[toc] | [prev] | [next] | [standalone]
| From | <paul.hermeneutic@gmail.com> |
|---|---|
| Date | 2015-11-15 21:54 -0700 |
| Message-ID | <mailman.356.1447649688.16136.python-list@python.org> |
| In reply to | #98838 |
The installer of some applications will replace the shebang to refer to a specific version of Python. By doing so, it avoids problems when someone upgrades the default Python version in the PATH. On Nov 14, 2015 11:00 PM, "eryksun" <eryksun@gmail.com> wrote: > On Sat, Nov 14, 2015 at 8:26 PM, Zachary Ware > <zachary.ware+pylist@gmail.com> wrote: > > > > "#!python" is a valid shebang for the Python Launcher for Windows. > > It's also a not-too-terrible placeholder for a Unix shebang meaning > > "whichever Python you want it to be". The better choice for use with > > both platforms would be "#!/usr/bin/env python", though. > > The "/usr/bin/env python" virtual command searches the directories in > PATH, trying each file extension from PATHEXT such as "python.COM", > "python.EXE", and so on. You can also search for other programs such > as "pypy". Note that qualifying "python" (but not other names) as > "python2" or "python3.5" makes the launcher use the registry instead > of searching PATH. > > "#!/usr/bin/python" may be better in some cases. This defaults to the > latest installed version of 2.x (or 3.x if no 2.x is installed) that's > configured in the Windows registry. Or specify "python2" or "python3" > to use the latest 2.x or 3.x. These commands can be configured to use > a particular major[.minor[-32]] version via the environment variables > PY_PYTHON, PY_PYTHON2, and PY_PYTHON3. Or you can configure them > instead by setting the "python", "python2" and "python3" keys in the > [defaults] section of the configuration file "%LOCALAPPDATA%\py.ini". > Note that the environment variable overrides the corresponding py.ini > key. > > When portability isn't a concern you can use a Windows path in the > shebang such as "#!C:\pypy40\pypy.exe". > > https://docs.python.org/3/using/windows.html#shebang-lines > -- > https://mail.python.org/mailman/listinfo/python-list >
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web