Message323681
| Author | Matthijs Kooijman |
|---|---|
| Recipients | Matthijs Kooijman, bethard, paul.j3, porton, rhettinger, zach.ware |
| Date | 2018-08-17.22:13:52 |
| SpamBayes Score | -1.0 |
| Marked as misclassified | Yes |
| Message-id | <1534544032.53.0.56676864532.issue34188@psf.upfronthosting.co.za> |
| In-reply-to |
| Content | |
|---|---|
One way to make the original example from Victor work, is to use the following action class:
class ConvertChoices(argparse.Action):
"""
Argparse action that interprets the `choices` argument as a dict
mapping the user-specified choices values to the resulting option
values.
"""
def __init__(self, *args, choices, **kwargs):
super().__init__(*args, choices=choices.keys(), **kwargs)
self.mapping = choices
def __call__(self, parser, namespace, value, option_string=None):
setattr(namespace, self.dest, self.mapping[value]) |
|
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2018-08-17 22:13:52 | Matthijs Kooijman | set | recipients: + Matthijs Kooijman, rhettinger, bethard, paul.j3, zach.ware, porton |
| 2018-08-17 22:13:52 | Matthijs Kooijman | set | messageid: <1534544032.53.0.56676864532.issue34188@psf.upfronthosting.co.za> |
| 2018-08-17 22:13:52 | Matthijs Kooijman | link | issue34188 messages |
| 2018-08-17 22:13:52 | Matthijs Kooijman | create | |