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: Clarify %(prog)s in argparse help formatter returns basename of sys.argv[0] by default
Type: behavior Stage: patch review
Components: Documentation, Library (Lib) Versions: Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, paul.j3, py.user, rhettinger, xtreak
Priority: normal Keywords: patch

Created on 2016-09-07 03:10 by py.user, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
argparse_sys-argv-0-part.diff py.user, 2016-09-07 03:10 Specifies term review
argparse_sys-argv-0-basename.diff py.user, 2019-04-07 06:46 Specifies term to basename
Pull Requests
URL Status Linked Edit
PR 12717 open py.user, 2019-04-07 15:27
Messages (4)
msg274729 - (view) Author: py.user (py.user) * Date: 2016-09-07 03:10
https://docs.python.org/3/library/argparse.html#argumentparser-objects
"prog - The name of the program (default: sys.argv[0])"

It doesn't take all sys.argv[0]. It splits sys.argv[0] and takes only the trailing part.

An example:

a.py

#!/usr/bin/env python3

import argparse
import sys

parser = argparse.ArgumentParser()
parser.add_argument("arg", help="The name is %(prog)s, the sys.argv[0] is " + sys.argv[0])
args = parser.parse_args()


The output in the console:

[guest@localhost bugs]$ ../bugs/a.py -h
usage: a.py [-h] arg

positional arguments:
  arg         The name is a.py and sys.argv[0] is ../bugs/a.py

optional arguments:
  -h, --help  show this help message and exit
[guest@localhost bugs]$


In the output we see that %(prog)s takes only trailing part of sys.argv[0] not all.

Applied a patch to the issue that specifies about part of sys.argv[0].
msg339287 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-04-01 09:27
Thanks for the report. To be little more clear it returns the "basename of sys.argv[0]" at [0] than the attached patch that says "uses part of ``sys.argv[0]``" .

[0] https://github.com/python/cpython/blob/62f9588663ebfea1735e9d142ef527395a6c2b95/Lib/argparse.py#L1638
msg339557 - (view) Author: py.user (py.user) * Date: 2019-04-07 06:46
@Karthikeyan Singaravelan
Thank you for the point. I added a new patch.
msg339558 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-04-07 06:48
CPython now accepts GitHub PRs. Please see the workflow at https://devguide.python.org . You can raise a PR against master branch.
History
Date User Action Args
2022-04-11 14:58:35adminsetgithub: 72179
2019-10-24 08:47:12xtreaksetnosy: + rhettinger
2019-04-07 15:27:29py.usersetstage: patch review
pull_requests: + pull_request12642
2019-04-07 06:48:42xtreaksetmessages: + msg339558
2019-04-07 06:46:19py.usersetfiles: + argparse_sys-argv-0-basename.diff

messages: + msg339557
2019-04-01 09:27:07xtreaksetnosy: + paul.j3, xtreak
title: In the argparse there is a misleading words about %(prog)s value -> Clarify %(prog)s in argparse help formatter returns basename of sys.argv[0] by default
messages: + msg339287

versions: + Python 3.7, Python 3.8, - Python 3.6
2016-09-07 03:10:52py.usercreate