我有一个文本文件,它是放在一起的几个XML文件。目标是将文本分成多个XML。从字符串列表中创建XML文件
我已经在这个片段中的代码来
def split_file(filename):
"""
Split the input file into separate files, each containing a single patent.
As a hint - each patent declaration starts with the same line that was
causing the error found in the previous exercises.
"""
f = open(filename, 'r').read().split('\n')
last_header_line = 0
counter_q_of_files = 0
for line in enumerate(f) :
lines_ls = []
## add that line to an object that will be converted in xml file on the next condition
## code here
if line[1] == '<?xml version="1.0" encoding="UTF-8"?>':
## Make an xml file out of the previously created object, from lines_ls[last_header_line:line[0]]
## code here
last_header_line = line[0]
counter_q_of_files = counter_q_of_files+1
我可以建立串(每未来XML行一个元素)的列表,该列表转换成XML文件?如果是,如何?
请修正您的代码的缩进。在函数名下,所有的代码都应该在函数内部。所以请修复你的缩进。 –
这是好吗? @cco –
感谢您的时间,现在我认为它是@cco –