[New-bugs-announce] [issue44208] argparse: Accept option without needing to distinguish "-" from "_" in arg_string

William Barnhart report at bugs.python.org
Fri May 21 13:51:20 EDT 2021


New submission from William Barnhart <williambbarnhart at gmail.com>:

An issue I encountered recently with argparse was when I tried running a script with its argument changed from something like:
```
parser.add_argument('--please_work')
```
and was replaced with:
```
parser.add_argument('--please-work')
```

I have not ever seen anyone add an argument where a function has two arguments existing in a function, such as please_work and please-work. I think this is a pretty safe feature to implement, plus it enforces good practices. So if I wrote something such as:

```
parser = argparse.ArgumentParser(description="check this out")
parser.add_argument('--please-work')
```

Then I could call the program using:
```
python3 test.py --please_work True
```
or:
```
python3 test.py --please-work True
```

----------
components: Library (Lib)
messages: 394135
nosy: wbarnha
priority: normal
severity: normal
status: open
title: argparse: Accept option without needing to distinguish "-" from "_" in arg_string
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44208>
_______________________________________


More information about the New-bugs-announce mailing list