python 写 yml文件
来源:互联网 发布:exo什么意思网络用语 编辑:程序博客网 时间:2024/05/29 05:01
yaml 另一种标记语言
import yamlimport osroot_path = os.path.abspath(os.path.dirname(__file__)).replace('\\', '/')print 'root_path: ' + root_pathconfig_file = os.path.abspath(os.path.join(root_path, 'test.yml')).replace('\\', '/')print 'config_file: ' + config_filefile_path = os.path.abspath(os.path.realpath(__file__)).replace('\\', '/')print 'file_path: ' + file_pathapp_name_1 = os.path.split(file_path)app_name_2 = os.path.splitext(file_path)print app_name_1, app_name_2app_name = app_name_1[1].split('.')[0]print app_namedef write_config_yaml(Node_number, branch_name): with open(config_file, 'a+') as f: default_Node_information = {} print default_Node_information default_Node_information['branch'] = [] print default_Node_information default_Node_information['branch'].append(branch_name) default_Node_information['branch'].append(app_name) dataMap = dict.fromkeys([Node_number]) dataMap[Node_number] = default_Node_information print dataMap yaml.dump(dataMap, f, default_flow_style=False) if __name__ == '__main__': f = open(config_file, 'w+') f.close() write_config_yaml(1, 'branch_name_1')
输出
pydev debugger: starting (pid: 6568)
root_path: C:/Users/b56853/workspace/Demo2/src/memo
config_file: C:/Users/b56853/workspace/Demo2/src/memo/test.yml
file_path: C:/Users/b56853/workspace/Demo2/src/memo/write_yaml.py
('C:/Users/b56853/workspace/Demo2/src/memo', 'write_yaml.py') ('C:/Users/b56853/workspace/Demo2/src/memo/write_yaml', '.py')
write_yaml
{}
{'branch': []}
{1: {'branch': ['branch_name_1', 'write_yaml']}}
test.yml文件中的内容:
1:
branch:
- branch_name_1
- write_yaml
0 0
- python 写 yml文件
- python 写yml文件
- .yml是什么文件
- opencv读取yml文件
- appspec.yml文件解析
- .yml是什么文件
- yaml文件 .yml
- java解析yml文件
- .yml文件语法
- @Value 读取yml 文件
- 如何使用opencv的c++接口来读取、写结构体数组到yml文件中
- opencv读写xml 、yml文件
- springboot注解读取yml文件
- yml
- yml
- python 写文件
- python 写xml文件
- python写文件
- OVAL
- sysbench 0.5 性能测试工具使用手册
- 《算法导论》读书笔记--顺序量选择
- 贾扬清分享_深度学习框架caffe
- ajax传递json字符串写法
- python 写 yml文件
- 【转】C++命名规范
- dns option view 块配置详解
- copy_from_user
- 解决webdriver定位#document内元素
- linux 手动安装gcc
- 利用系统浏览器下载应用
- Java关键字final、static使用总结
- Win7下QQ导致电影音乐声音变小的解决方法