Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:
Depending on how you want to expose enums to end-users, some reasonable options already exist: import argparse from enum import Enum class Shake(Enum): VANILLA = 7 CHOCOLATE = 4 COOKIES = 9 MINT = 3 # Option 1 ap = argparse.ArgumentParser() ap.add_argument('shakes', nargs=2, choices=Shake, type=Shake.__getitem__) ns = ap.parse_args(['VANILLA', 'MINT']) print(ns) # Option 2 ap = argparse.ArgumentParser() ap.add_argument('shakes', nargs=2, choices=Shake.__members__) ns = ap.parse_args(['VANILLA', 'MINT']) ns.shakes = [Shake[name] for name in ns.shakes] print(ns) In Option 1, the user sees choices of: {Shake.VANILLA,Shake.CHOCOLATE,Shake.COOKIES,Shake.MINT} In Option 2, the user sees choices of: {VANILLA,CHOCOLATE,COOKIES,MINT} ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue25061> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com