如何在Python中使用argparse获取命令行参数?
我希望能够在通过命令行传递选项后保存整数值。理想情况下,它是:
python thing.py -s 1 -p 0 1 2 3 -r/-w/-c
-s
- 存储以下整数-p - 存储以下整数
最后部分只能是三个选项之一(-r、 -w 或 -c),具体取决于它的内容是我需要做的。
我一直在尝试阅读教程,但它们都使用相同的两个示例,但没有解释如何在 -option
之后存储整数。
I want to be able to save integer values after an option is passed through the command line. Ideally it would be:
python thing.py -s 1 -p 0 1 2 3 -r/-w/-c
-s
- store the following integer-p
- store the following integers
The final part can be only one of the three options (-r, -w, or -c), depending on what it is I need to do.
I've been trying to read tutorials but they all use the same two examples that don't explain how to store integers after a -option
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)