Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

argparse Prints options per flag name when only once is necessary #101599

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
@Harrison-O

Description

@Harrison-O

Bug report

When running a command line program with the--help/-h flag withargparse, if another flag has multiple names and choices to pick from, the options are printed multiple times instead of just once. For example, the program below:

importargparseif__name__=="__main__":parser=ArgumentParser()parser.add_argument('-m','--metric',choices=["accuracy","precision","recall"])parser.parse_args(["-h"])

Will print

usage: argparse_test.py [-h] [-m {accuracy,precision,recall}]options:  -h, --help            show thishelp message andexit  -m {accuracy,precision,recall}, --metric {accuracy,precision,recall}

Notice that the flag choices are printed out twice, once for each flag name. This is redundant and negatively impacts readability. The program should output:

usage: argparse_test.py [-h] [-m {accuracy,precision,recall}]options:  -h, --help            show thishelp message andexit  -m, --metric {accuracy,precision,recall}

Your environment

  • CPython versions tested on: 3.10.6
  • Operating system and architecture: Windows 11 with WSL 2

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Status

    Doc issues

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp