sys模块【内置模块】
sys
模块提供了与 Python 解释器及其环境交互的功能,如处理命令行参数和退出程序等
引入sys
import sys
sys模块
# 返回 "模块搜索路径" 列表
res = sys.path # ['D:\\d_pycharm_program\\python_test', 'D:\\d_pycharm_program\\python_test', 'E:\\a_e\\软件\\PyCharm 2023.3.3\\plugins\\python\\helpers\\pycharm_display', 'C:\\Users\\26945\\AppData\\Local\\Programs\\Python\\Python39\\python39.zip', 'C:\\Users\\26945\\AppData\\Local\\Programs\\Python\\Python39\\DLLs', 'C:\\Users\\26945\\AppData\\Local\\Programs\\Python\\Python39\\lib', 'C:\\Users\\26945\\AppData\\Local\\Programs\\Python\\Python39', 'D:\\d_pycharm_program\\python_test\\.venv', 'D:\\d_pycharm_program\\python_test\\.venv\\lib\\site-packages', 'E:\\a_e\\软件\\PyCharm 2023.3.3\\plugins\\python\\helpers\\pycharm_matplotlib_backend']
# 返回终端中所传的参数列表
res = sys.argv # ['test.py', '1', '2', '3']
res = sys.argv[0] # test.py
sys.argv示例
查看python版本
import sys
print(sys.version) # 3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)]