笨方法学python之import sys与from sys import argv的区别,,这是在网上看到的一个
笨方法学python之import sys与from sys import argv的区别,,这是在网上看到的一个
这是在网上看到的一个大神的解答:
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参数。
笨方法学python之import sys与from sys import argv的区别
相关内容
- python对影评进行评论分析,形成词云图,,1 # -*- co
- Python O,,oct() :把一个
- 命令行运行python -m http.server报错,,最近在学习网站搭建
- python简单模拟博客园系统,,# 用代码模拟博客园
- selenium+python +unitest 环境安装,,Python环境:3
- python---win32gui:winAPI操作,,python操作wi
- python爬虫:两种方法模拟登录博客园,,第一方法用第三
- Python标识符和关键字,,本节内容如下:什么是
- Python内置函数之str(),,class str(
- Python 文档操作,,from docx
评论关闭