Python3中的sys模块提供了访问由解释器使用和维护的一些变量和与解释器强烈交互的函数
sys.argv
获取传递给Python脚本的参数列表,sys.argv[0]代表脚本本身,sys.argv[n]代表第n个参数
sys.path
获取模块的搜索路径,初始化时使用PYTHONPATH环境变量的值
sys.version
获取Python解释器的版本
sys.maxsize
获取最大int值,受平台限制
sys.platform
获取操作系统平台标识符
sys.exit(n)
退出解释器,相当于函数exit(n),n默认为0表示正常退出
sys.stdout.write('Hello')
将字符写到标准输出,多用于进度条
sys.stdin.readline()
读取标准输入
import sys import time # 在控制台终端执行,在Pycharm的控制台貌似不好使 for i in range(51): sys.stdout.write("Loading: %" + str(i*2)+"["+"#" * i + "] ") sys.stdout.flush() time.sleep(0.15)