码迷,mamicode.com
首页 > 其他好文 > 详细

xml2txt todolater

时间:2017-04-24 10:01:47      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:main   path   nbsp   lines   readline   test   lis   code   txt   

#!/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

标签:main   path   nbsp   lines   readline   test   lis   code   txt   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!