[docs] [issue27992] In the argparse there is a misleading words about %(prog)s value

py.user report at bugs.python.org
Tue Sep 6 23:10:53 EDT 2016


New submission from py.user:

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 at 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 at 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].

----------
assignee: docs at python
components: Documentation, Library (Lib)
files: argparse_sys-argv-0-part.diff
keywords: patch
messages: 274729
nosy: docs at python, py.user
priority: normal
severity: normal
status: open
title: In the argparse there is a misleading words about %(prog)s value
type: behavior
versions: Python 3.6
Added file: http://bugs.python.org/file44420/argparse_sys-argv-0-part.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27992>
_______________________________________


More information about the docs mailing list