How can I use python's argparse with a predefined argument string?

前端 未结 4 1652
星月不相逢
星月不相逢 2020-12-09 09:23

I want to use the pythons argparse module to parse my cli parameter string. This works for the parameters a pass from terminal, but not with a given string.

         


        
4条回答
  •  难免孤独
    2020-12-09 09:51

    Just like the default sys.argv is a list, your arguments have to be a list as well.

    args = parser.parse_args([argString])
    

提交回复
热议问题