Matthijs Kooijman <matthijskooij...@gmail.com> added the comment:

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])

----------

_______________________________________
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