This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients barry, bethard, desbma, leycec, paul.j3, rhettinger
Date 2019-08-30.06:04:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1567145089.48.0.466664335213.issue25061@roundup.psfhosted.org>
In-reply-to
Content
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}
History
Date User Action Args
2019-08-30 06:04:49rhettingersetrecipients: + rhettinger, barry, bethard, paul.j3, desbma, leycec
2019-08-30 06:04:49rhettingersetmessageid: <1567145089.48.0.466664335213.issue25061@roundup.psfhosted.org>
2019-08-30 06:04:49rhettingerlinkissue25061 messages
2019-08-30 06:04:49rhettingercreate