Case insensitive argparse choices

前端 未结 3 1167
鱼传尺愫
鱼传尺愫 2020-12-15 02:35

Is it possible to check argparse choices in case-insensitive manner?

import argparse
choices = [\"win64\", \"win32\"]
parser = argparse.ArgumentParser()
pars         


        
3条回答
  •  执笔经年
    2020-12-15 02:47

    Keeping the case information would also be possible with a one liner:

    type = lambda arg: {x.lower(): x for x in choices}[arg.lower()],
    

    Where choices would be the same list as passed to the choices parameter.

提交回复
热议问题