如何读取可变长度命令行参数
我想给我的脚本输入命令行。 其输入参数为:
- 的脚本
- 。
- 我 第一个命令,其中我将通过命令行传递多个ID
myScript.py ID ID1,ID2,ID3 ...
第二个命令,其中我将在末端a'-f'标志,该标志表示强制,必须执行该操作。
myScript.py ID 123,21,1,900 -F
我的问题是,我应该在脚本中阅读并使用这些参数? 谢谢 !
I want to give command line inputs to my script.
which has input arguments as :
- my script.py
- mode name (which is id)
- id numbers ( passed by ',' separations
first command, in which I would pass multiple ids through command linemyscript.py id id1,id2,id3...
second command, where I would a '-f' flag at the end which denotes force and it must do that operation.
myscript.py id 123,21,1,900 -f
My question is, how should I read in and use these arguments in the script?
Thank you !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从
sys
库中获得参数。基本实现
如果您需要作为字典格式,则可以查看 this
You can get argument from
sys
library.Basic implementation
If you want as dictionary format you can view this