New submission from Victor Porton <por...@narod.ru>:

The below code produces "rock", but it should produce "a". This (to use dict 
value instead of the key by argparse result) is both to be a new useful feature 
(for example to map strings in a command line to certain functions or classes 
provided as dict values) and conform to intuition better.

My feature proposal breaks backward compatibility, but I think no reasonable 
programmer wrote it in such a way that he relied on the current behavior for 
`dict` values for `choices`.

import argparse

parser = argparse.ArgumentParser(prog='game.py')
parser.add_argument('move', choices={'rock':'a', 'paper':'b', 'scissors':'c'})
print(parser.parse_args(['rock']))

----------
components: Library (Lib)
messages: 322142
nosy: porton
priority: normal
severity: normal
status: open
title: Use dicts to "transform" argparse arguments to values
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34188>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to