博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
笨方法学python之import sys与from sys import argv的区别
阅读量:6980 次
发布时间:2019-06-27

本文共 928 字,大约阅读时间需要 3 分钟。

这是在网上看到的一个大神的解答: 

sys is a module that contains “system functionality”. sys.argv is a list containing your script’s command line arguments. One way to use it would be to write import sys and then sys.argv to access it.

from module import names is an alternative way to import a module that allows you to access the given names without naming the module. That is writing from sys import argv allows you to just write argv whereas import sys would require you to write sys.argv instead.

翻译如下:sys是一个模块,里面包含一些系统函数,sys.list是一个列表,其中包含你的脚本想运行的一些命令行参数,使用他的一个方法就是书写:sys.argv。

from module import names是一种变相导入模块的方法,允许你直接使用变量名(names)而不需要导入模块名。from sys import argv这种方式可以允许你直接使用argv,而不需要再这样sys.argv书写。

下面是自己的理解: 

import sys 把sys模块包含的所有函数和参数不管你需不需要,统统包含进来,就好比C语言中的#include()指令 
from sys import argv 导入sys中的argv参数,并不会将sys模块中的所有函数和变量包含进来,只会导入argv变量,这也就是所谓的让你的程序保持精简。脚本中使用到argv参数时,就会调用sys中的argv参数。

转载于:https://www.cnblogs.com/Jzeng666/p/9589547.html

你可能感兴趣的文章
阿里巴巴开源技术汇总:115个软件(一)
查看>>
ios开发之系统信息
查看>>
遮罩效果的实现
查看>>
Android之NDK开发的简单实例
查看>>
日志分析工具splunt
查看>>
元素宽高的获取
查看>>
SQLSERVER存储过程基本语法使用
查看>>
sql server时间转换
查看>>
CDH大数据集群安全风险汇总
查看>>
数据结构实验之链表一:顺序建立链表
查看>>
docker Rails Permission denied @ dir_s_mkdir
查看>>
【二分答案】【最短路】bzoj1614 [Usaco2007 Jan]Telephone Lines架设电话线
查看>>
【贪心】Google Code Jam Round 1A 2018 Waffle Choppers
查看>>
【转载】【贪心】各种覆盖问题
查看>>
HDU 6051 - If the starlight never fade | 2017 Multi-University Training Contest 2
查看>>
insert into与insert ignore以及replace into的区别
查看>>
【网络流24题】最小路径覆盖问题
查看>>
java分享第五天(数组)
查看>>
数组与纠结的排序篇
查看>>
Linux命令-安装zip和unzip命令
查看>>