我有一個文本文件,它是放在一起的幾個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 –