一般的文件 读取的包含换行符 是数组格式
# open def get_yaml(file_path): with open(file_path,encoding='utf-8') as fo: print(fo.readlines()) if __name__ == '__main__': get_yaml('../configs/evn.yaml') ''' ['Login: # 登录整个模块\n', ' login: # 登录方法\n', ' url: /account/sLogin\n', ' method: post\n', ' logout: # 退出方法\n', ' url: /account/logout\n', ' method: post'] '''
用yaml包 读取的数据 不包含换行符等 是字典格式
# 读取yaml 文件 获得字典类型的数据 import yaml def get_yaml(yaml_path): with open(yaml_path,encoding='utf-8') as fo: yaml_data=yaml.safe_load(fo.read()) return yaml_data if __name__ == '__main__': print(get_yaml('../data/env.yaml')) ''' {'Login': {'login': {'path': '/account/slogin', 'method': 'POST'}, 'logout': {'path': '/account/logout', 'method': 'POST'}}} '''
标签:__,文件,get,yaml,path,open,fo From: https://www.cnblogs.com/haha1988/p/17635321.html