社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

什么是Python第一个参数?系统argv[0]或系统argv[1]

Sabrina • 4 年前 • 361 次点击  

根据 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的人感到困惑。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54961
 
361 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Gabe Spound
Reply   •   1 楼
Gabe Spound    4 年前

sys.argv[0] 是脚本的名称。从技术上讲,它是“第一”参数,但通常对您没有用处,除非您不知道正在执行的文件的名称。 sys.argv[1] ,是脚本名称之后的第一个参数的名称,因此是第一个有用的参数。