いくつかの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の1行につき1つの要素)を作成し、XMLファイルにそのリストを変換できますか?はいの場合、どうですか?
コードのインデントを修正してください。関数名の下には、すべてのコードが関数内にある必要があります。だからあなたの押し込みを修正してください。 –
これは問題ありませんか? @cco –
あなたの時間をありがとう、今私はそれが@ccoだと思う –