open

Python open() 函数

罕用技巧:

with open(path, encoding="utf-8") as file:    data = yaml.safe_load(file)    return data[key]

os

Python OS 文件/目录办法

罕用技巧:

import os# 以后文件所在门路dir_path = os.path.dirname(os.path.abspath(__file__))# 拼接门路case_path = os.path.join(dir_path, "test_case")# 返回当前工作目录cur_path = os.getcwd()# 返回绝对路径os.path.abspath(path)os.path.abspath(__file__)  # 蕴含文件名# 以数字mode的mode创立一个名为path的文件夹.默认的 mode 是 0777 (八进制)os.mkdir(path[, mode])# 如果门路 path 存在,返回 True;如果门路 path 不存在,返回 Falseos.path.exists(path)# 把目录和文件名合成一个门路os.path.join(path1[, path2[, ...]])# 返回path的实在门路os.path.realpath(path)os.path.realpath(__file__)  # 蕴含文件名# 返回文件门路os.path.dirname(path)# 联合 os.path.realpath(__file__); os.path.abspath(__file__) 应用os.path.dirname(os.path.realpath(__file__))  # 不蕴含文件名os.path.dirname(os.path.abspath(__file__))  # 不蕴含文件名# 判断运行零碎内核,win or Linuxos.name

os.path

sys

Python中sys模块

import sys# 获取运行版本信息,例如python的版本信息sys.version_info# 获取运行平台信息,win or Linuxsys.platform