据 https://www.tutorialspoint.com/python/python_command_line_arguments.htm
first argument is always script name and it is also being counted in number of arguments.
这是sys.argv[0]
但是,当我阅读其他教程时,例如
https://www.cyberciti.biz/faq/python-command-line-arguments-argv-example/
它说第一个参数是sys.argv[1]
#!/usr/bin/python
__author__ = 'nixCraft'
import sys total = len(sys.argv)
cmdargs = str(sys.argv)
print ("The total numbers of args passed to the script: %d " % total)
print ("Args list: %s " % cmdargs)
# Pharsing args one by one
print ("Script name: %s" % str(sys.argv[0]))
print ("First argument: %s" % str(sys.argv[1]))
print ("Second argument: %s" % str(sys.argv[2]))
哪一个是正确的,应该遵循?
对于那些刚刚开始学习编程和Python的人来说,这尤其令人困惑。
翻翻过去那场雪
相关分类