我想在 argparse 模块中有一些选项,例如 --pm-export
但是当我尝试像 args.pm-export
一样使用它时,我得到了错误没有属性pm
。我该如何解决这个问题?是否可以在命令行选项中有 -
?
最佳答案
作为 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
所以你应该使用 args.pm_export
。
关于python - 在 argparse 中有一个带有破折号的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12834785/