python小程序-0016
来源:互联网 发布:淘宝网如何注册网店 编辑:程序博客网 时间:2024/05/16 17:34
第16题: 将 第 0013 题中的 city.xls 文件中的内容写到 city.xml 文件中,如下所示:
<?xmlversion="1.0" encoding="UTF-8"?><root><citys><!-- 城市信息-->{ "1" : "上海", "2" : "北京", "3" : "成都"}</citys></root>
#!/usr/bin/env python3# -*- coding : utf-8 -*-from pyexcel_xls import get_datafrom xml.dom.minidom import Documentimport jsondata = get_data('city.xls')doc = Document()root_node = doc.createElement("root")doc.appendChild(root_node)stu_node = doc.createElement("citys")root_node.appendChild(stu_node)stu_node.appendChild(doc.createComment('\n\t城市信息\n'))citystr = "{\n"for ele in data['city']: for i in range(len(ele)): if i == 0: citystr += "\t" citystr += "\"" + str(ele[i]) + "\"" citystr += " : " else: citystr += "\"" + str(ele[i]) + "\"" citystr += "\n"citystr += "}"print(citystr)dic_node = doc.createTextNode(citystr)stu_node.appendChild(dic_node)with open("city.xml",'wb') as s: s.write(doc.toprettyxml(indent = "",newl = "\n",encoding = "utf-8"))
阅读全文
0 0
- python小程序-0016
- python小程序
- python 小程序
- python小程序
- python 简单小程序
- python小程序集锦
- python爬虫小程序
- Python小程序
- python小程序
- python练习小程序
- Python入门小程序
- python 查询小程序
- [python] 小程序
- Python里小程序
- Python通讯录小程序
- Python小程序
- python界面小程序
- python小程序
- RePlugin初体验
- 1063. 计算谱半径(20)
- MariaDB命令详解
- windows7一些骚操作
- CUDA编程(二) CUDA初始化与核函数
- python小程序-0016
- Linux与windows文件共享ssh安装配置使用
- curl传输文件实例
- c 语言中一些特殊函数的整理
- html中的meta
- matlab: strcat用法
- DB2命令大全
- ORA-00845: MEMORY_TARGET not supported on this system
- 用位运算实现四则运算之加减乘除