一、模块初识:
Python有大量的模块,从而使得开发Python程序非常简洁。类库有包括三中:
- Python内部提供的模块
- 业内开源的模块
- 程序员自己开发的模块
1、Python内部提供一个 sys 的模块,
① 其中的 sys.argv 用来捕获执行执行python脚本时传入的参数:
import sys strings = sys.argv print(strings) # 所有参数 类型为列表 # ['start.py', 'hello', 'world'] print(strings[0]) # 脚本名本身 # start.py print(strings[1]) # 第一个参数 # hello print(strings[2]) # 第二个参数 # world print(strings[-1]) # 倒数第一个参数 # world $ python test.py helo world 执行脚本
② sys.stdin信息输入:
读取的文件:
我越无所适从
越会事与愿违
在交错的时空
灵魂加速下坠
Here we are, here we are, here we are