This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Fix -x option documentation
Type: Stage: resolved
Components: Windows Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: paul.moore, serhiy.storchaka, steve.dower, terry.reedy, tim.golden, vstinner, zach.ware
Priority: normal Keywords: patch

Created on 2017-11-16 15:49 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4423 merged vstinner, 2017-11-16 16:02
PR 4424 closed vstinner, 2017-11-16 16:27
PR 4475 merged vstinner, 2017-11-20 15:10
PR 4477 merged python-dev, 2017-11-20 16:08
Messages (17)
msg306365 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-16 15:49
Python has a -x option documented as a "DOS specific hack only":
https://docs.python.org/dev/using/cmdline.html#cmdoption-x

Python doesn't support MS-DOS since Python 2.1:
https://www.python.org/dev/peps/pep-0011/#no-longer-supported-platforms

I propose to deprecate the option in Python 3.7: using it emits a DeprecationWarning, option deprecated in the documentation; and remove the option in Python 3.8.
msg306366 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-16 16:03
The note in the documentation is wrong: the line number is correct when using the -x option, even if the first line is skipped.

Example with Python 2.7:
---
$ cat x.py 
print(1)
print(2)
x

$ python2 x.py 
1
2
Traceback (most recent call last):
  File "x.py", line 3, in <module>
    x
NameError: name 'x' is not defined

$ python2 -x x.py 
2
Traceback (most recent call last):
  File "x.py", line 3, in <module>
    x
NameError: name 'x' is not defined
---

Attached PR 4423 fixes Python 2.7 documentation.
msg306369 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-11-16 16:21
Python still supports Windows.
msg306371 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-16 16:26
> Python still supports Windows.

What is the use case for this option on Windows?

On Unix, the first line is usually used for the shebang, a line like:

   #!/usr/bin/env python3

But this shebang is seen as a comment in Python and Python simply ignore the shebang, seen as a comment.
msg306376 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-11-16 16:42
The same as on DOS.

Change the extension of the Python script from .py to .bat, and insert the following first line:

@path\to\python -x %0 %1 %2 %3 %4 %5 %6 %7 %8 %9

Now you can run it as a bat-file. The command in the first line will run Python, passing the name of this file and up to 9 arguments (you can make it passing more than 9 arguments, but I don't remember the syntax). "@" disables printing this command itself. The first line is not valid Python syntax, but due to the -x option it will be skipped.
msg306377 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-16 16:46
> @path\to\python -x %0 %1 %2 %3 %4 %5 %6 %7 %8 %9

Oh wow, I never saw that before.

There is now a "py" launcher on Windows, do we still need such "hack"?
msg306381 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-11-16 16:55
Yes, of course. The py launcher is not an alternative to this "hack". It just allows you to specify just "py" (with possible options -2, -3, -3.6) instead of hardcoding the full name to the Python binary or add the path to directory containing the Python binary to your PATH.
msg306472 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-11-18 05:45
So the hack is not specific to DOS but is still needed for Windows .bat files. They run in Command Prompt, which was once called the DOS box.  (I don't know if they work unaltered in PowerShell.)  It seems that the doc should be updated.
msg306475 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-11-18 07:44
The current short line of the description was enough to me for understanding what is the purpose of this option and how it can be used (I didn't use Windows for more than 10 years). But I was surprised not founding more detailed information about this feature in the documentation. Definitely it should be better documented. Most of users will have no ideas about this feature.
msg306476 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-11-18 08:47
It seems to me that the best way is to add the following line at the start of the script:

    @path\to\python -x %0 %* & exit /b

Or

    @py -3 -x %0 %* & exit /b
msg306477 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-18 09:16
Ok, I will update the doc instead of deprecating the option.
msg306551 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-20 15:08
New changeset 733b5f3f2f2425fa939d71bc317f2e0f1968c2a0 by Victor Stinner in branch '2.7':
bpo-32050: Fix -x option documentation (#4423)
https://github.com/python/cpython/commit/733b5f3f2f2425fa939d71bc317f2e0f1968c2a0
msg306561 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-20 16:08
New changeset c5a2071586f735d2a61d1756e7011cfbb6ce86c9 by Victor Stinner in branch 'master':
bpo-32050: Fix -x option documentation (#4475)
https://github.com/python/cpython/commit/c5a2071586f735d2a61d1756e7011cfbb6ce86c9
msg306563 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-20 16:16
New changeset 60a376cf0023d1070329d0e861a5596637ff3275 by Victor Stinner (Miss Islington (bot)) in branch '3.6':
bpo-32050: Fix -x option documentation (GH-4475) (#4477)
https://github.com/python/cpython/commit/60a376cf0023d1070329d0e861a5596637ff3275
msg306564 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-20 16:18
I removed the note from the documentation since it was outdated.

Serhiy, Terry: Do you want to work on a patch to rephrase the "DOS specific hack only" sentence?

> @py -3 -x %0 %* & exit /b

I'm not a BATCH expert, so I don't know if this command works on all Windows version, or even on MS-DOS. So I'm not confident to propose such doc change myself, sorry.
msg306566 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-11-20 16:52
I don't know either.  Once of the Windows experts should review and revise.
msg306869 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-24 01:24
The initial proposition was to *deprecate* the option.

In the meanwhile, I removed an outdated note.

While the documentation is not perfect, I don't feel confortable to fix it, so I left it unchanged.

I close this PR. Please open a new issue (with a PR if possible ;-)) if you want to enhance -x option documentation.
History
Date User Action Args
2022-04-11 14:58:54adminsetgithub: 76231
2017-11-24 01:24:27vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg306869

stage: patch review -> resolved
2017-11-20 16:52:25terry.reedysetmessages: + msg306566
2017-11-20 16:18:22vstinnersetmessages: + msg306564
2017-11-20 16:16:10vstinnersetmessages: + msg306563
2017-11-20 16:08:24python-devsetpull_requests: + pull_request4414
2017-11-20 16:08:05vstinnersetmessages: + msg306561
2017-11-20 15:12:48vstinnersettitle: Deprecated python3 -x option -> Fix -x option documentation
2017-11-20 15:10:48vstinnersetpull_requests: + pull_request4410
2017-11-20 15:08:46vstinnersetmessages: + msg306551
2017-11-18 09:16:56vstinnersetmessages: + msg306477
2017-11-18 08:47:13serhiy.storchakasetmessages: + msg306476
2017-11-18 07:44:51serhiy.storchakasetmessages: + msg306475
2017-11-18 05:45:32terry.reedysetnosy: + terry.reedy
messages: + msg306472
2017-11-16 16:55:09serhiy.storchakasetmessages: + msg306381
2017-11-16 16:46:56vstinnersetnosy: + paul.moore, tim.golden, zach.ware, steve.dower
messages: + msg306377
components: + Windows, - Interpreter Core
2017-11-16 16:42:46serhiy.storchakasetmessages: + msg306376
2017-11-16 16:27:13vstinnersetpull_requests: + pull_request4371
2017-11-16 16:26:53vstinnersetmessages: + msg306371
2017-11-16 16:21:32serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg306369
2017-11-16 16:03:29vstinnersetmessages: + msg306366
2017-11-16 16:02:14vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request4370
2017-11-16 15:49:19vstinnercreate