Closed scrummyin closed 1 month ago
This could be done something like this:
diff --git a/Lib/json/tool.py b/Lib/json/tool.py
index 0490b8c0be..e0e196c722 100644
--- a/Lib/json/tool.py
+++ b/Lib/json/tool.py
@@ -16,8 +16,11 @@
from pathlib import Path
+_python_exe = sys.executable
+
+
def main():
- prog = 'python -m json.tool'
+ prog = f'{_python_exe} -m json.tool'
description = ('A simple command line interface for json module '
'to validate and pretty-print JSON objects.')
parser = argparse.ArgumentParser(prog=prog, description=description)
$ ./python.exe -m json.tool -h
usage: /Users/hugo/github/cpython/python.exe -m json.tool [-h] [--sort-keys] [--no-ensure-ascii] [--json-lines] [--indent INDENT | --tab | --no-indent | --compact]
[infile] [outfile]
...
Or (less helpfully?) without the full path:
diff --git a/Lib/json/tool.py b/Lib/json/tool.py
index 0490b8c0be..43754cdd59 100644
--- a/Lib/json/tool.py
+++ b/Lib/json/tool.py
@@ -12,12 +12,16 @@
"""
import argparse
import json
+import os
import sys
from pathlib import Path
+_python_exe = os.path.basename(sys.executable)
+
+
def main():
- prog = 'python -m json.tool'
+ prog = f'{_python_exe} -m json.tool'
description = ('A simple command line interface for json module '
'to validate and pretty-print JSON objects.')
parser = argparse.ArgumentParser(prog=prog, description=description)
$ ./python.exe -m json.tool -h
usage: python.exe -m json.tool [-h] [--sort-keys] [--no-ensure-ascii] [--json-lines] [--indent INDENT | --tab | --no-indent | --compact] [infile] [outfile]
...
pip does something along these lines:
I did a little more than that with #91819 , partially to guarantee that something comes out when sys.executable might fail, since it can return None
.
The general issue is a duplicate of #66436.
Leaving this issue open as json.tools
specific issue.
Feature or enhancement
Display the invoked executable name such as python3 or python.exe so users can copy and paste without having to translate, for tools such as ast and json.tool.
Pitch
The example below shows a before usage of json.tool and an after below.
becomes
This is more friendly to users on windows because of the
.exe
extension and to *nix users who's OS might install python 3 at python3 and have an old python2 version somewhere else. Or as we move into the future and some OS drop python2 but never rectify python point to python3.Linked PRs