python argv 详解_【python 官方文档翻译解释,都是知识点】sys.argv

开门见山

什么是 sys.argv

要弄清这个问题,我们就要先明白,什么是 sys?

sys 是Python 常用的一个标准库,封装系统部分信息和接口

【官方文档】

This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It is always available.

【我自个的翻译】

这个模块提供对一些解释程序变量的使用或维护,以及解释程序的强交互性方法。这个模块是一直可以使用的。

我,英语飞屋,有解释更好的私信我,我改鸭。

sys 模块我们知道了,那 sys.argv 呢?

【官方文档】

The list of command line arguments passed to a Python script.

argv[0] is the script name (it is operating system dependent whether this is a full pathname or not).

if the command was executed using the -c command line option to the interpreter, argv[0] is set to the string '-c'.

if no script name was passed to the Python interpreter, argv[0] is the empty string.

【又是自个的翻译】

将命令行参数传递给 Python 脚本的列表。

argv[0] 是脚本名(路径名是否是完整的要看操作系统)。

如果命令行是使用 -c 做为命令行参数传递给解释程序,argv[0] 就是字符串 '-c'

如果没有脚本名传递给 Python 解释器,argv[0] 就是个空字符串

怎么理解?

· argv,argument variable,参数变量英文的简写。

· argv[] 是个列表,用于存放命令行参数的列表。

· 路径名的完整是和操作系统有关的。

· 它举了个 '-c' 的例子。

sys.argv[0] 代表本体文件路径。sys.argv[1] 代表第一个参数,sys.argv[2] 代表第二个参数,以此类推。

没有要传递的参数,sys.argv[0] 就是空字符。

【常用方法】

· sys.argv[1: ]    从第一个命令行参数到最后一个命令行参数

· sys.argv[1][2: ]    第一个命令行参数,去掉前两个字节

· 既然是列表,用列表常用的方法就好了。

好啦~先到这里!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值