根据 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]
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的人感到困惑。
sys.argv[0] 是脚本的名称。从技术上讲,它是“第一”参数,但通常对您没有用处,除非您不知道正在执行的文件的名称。 sys.argv[1] ,是脚本名称之后的第一个参数的名称,因此是第一个有用的参数。