Having options in argparse with a dash

前端 未结 5 1445
长发绾君心
长发绾君心 2020-12-12 18:58

I want to have some options in argparse module such as --pm-export however when I try to use it like args.pm-export I get the error that there is n

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-12 19:21

    As indicated in the argparse docs:

    For optional argument actions, the value of dest is normally inferred from the option strings. ArgumentParser generates the value of dest by taking the first long option string and stripping away the initial -- string. Any internal - characters will be converted to _ characters to make sure the string is a valid attribute name

    So you should be using args.pm_export.

提交回复
热议问题