首页 > 其他 > 详细

xml2txt todolater

时间:2017-04-24 09:45:09      阅读:130      评论:0      收藏:0      [点我收藏+]

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os

def xml2txt(xml_path, txt_path, txt_name):
    files = os.listdir(xml_path)
    txt_path_cur = txt_path + txt_name
    txt_op = open(txt_path_cur, "w")
    for file in files:
        xml_file_path = xml_path + file
        file_op = open(xml_file_path,‘r‘)
        for line in file_op.readlines():
            if "<module_name>" in line:
                module_name_true = line[13:-14]
                txt_op.write("%s\n" % module_name_true)
            elif "<sub_module_name>" in line:
                sub_module_name_true = line[17:-18]
                txt_op.write("%s\n" % sub_module_name_true)
            else:
                continue
        file_op.close()
    txt_op.close()


if __name__ == "__main__":
    xml_path_real = "D:\\code\\test\\"
    txt_path_real = "D:\\code\\test\\"
    txt_name_real = "txt_test.txt"
    xml2txt(xml_path_real, txt_path_real, txt_name_real)




xml2txt todolater

原文:http://www.cnblogs.com/xmlee/p/6755011.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!