Python sys模块
sys模块
用于提供对解释器相关的操作
sys.argv
# 命令行参数List,第一个元素是程序本身路径
sys.exit(n)
# 退出程序,正常退出时exit(0)
sys.version
# 获取Python解释程序的版本信息
sys.maxint
# 最大的Int值
sys.path
# 返回模块的搜索路径,初始化时使用PYTHONPATH环境变量的值
sys.platform
# 返回操作系统平台名称
sys.stdout.write('please:')
val = sys.stdin.readline()[:-1]
测试脚本
import sys
print(sys.stdout.write("please:")) # 进度条使用
val = sys.stdin.readline()[:-1] # 读取键盘的一次输入
print(sys.platform) # 返回操作系统平台名称
print(sys.path) # 返回模块的搜索路径
print(sys.version) # 获取Python解释程序的版本信息
print(sys.argv) # 命令行参数List,第一个元素是程序本身路径
# 输出结果
please:7
darwin
['/Users/evescn/Documents/GitHub/python', '/Users/evescn/Documents/GitHub/python', '/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_display', '/Users/evescn/.conda/envs/python/lib/python310.zip', '/Users/evescn/.conda/envs/python/lib/python3.10', '/Users/evescn/.conda/envs/python/lib/python3.10/lib-dynload', '/Users/evescn/.conda/envs/python/lib/python3.10/site-packages', '/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend']
3.10.11 (main, May 15 2023, 19:29:30) [Clang 14.0.6 ]
['/Users/evescn/Documents/GitHub/python/1.py']
标签:evescn,Users,lib,Python,sys,python,模块,print
From: https://www.cnblogs.com/evescn/p/17501329.html