我在ubuntu上的python2.7和3.5中收到一个错误,expat无法读取第一个元素。在
xml.parsers.expat.ExpatError: no element found: line 1, column 0
第1行看起来很正常,并且之前已经过解析。在
^{pr2}$我的剧本是
import xmltodict
'''import csv
import re
from sys import argv
SCRIPT, FILENAME = argv
def out_file_name(file_name):
"""take an input file and keep the name with appended _clean"""
file_parts = file_name.split(".",)
output_file = file_parts[0] + '_clean.' + file_parts[1]
return output_file'''
with open('20160319RHIL0_edit.xml', 'r+') as f:
my = xmltodict.parse(f.read())
eventID = my['meeting']["@id"]
location = my['meeting']["@venue"]
eventDate = my['meeting']["@date"]
meeting = [eventID, location, eventDate]
raceFields = []
for race in my['meeting']['race']:
raceArr = []
# race.append(race["@id"],race["@number"])
raceNum = race["@number"]
raceID = race["@id"]
# print(race["@id"] + '\t' + race["@number"])
for noms in race['nomination']:
saddle = noms["@number"]
horse = noms["@horse"]
horseId = noms["@id"]
barrier = noms["@barrier"]
career = noms["@career"]
rating = noms["@rating"]
sexA = noms["@sex"]
# trackRec = noms["@thistrack"]
age = noms["@age"]
description = noms["@description"]
# price = noms["@pricestarting"]
weights = noms["@weight"]
# print(saddle + '\t' + horse + '\t' + horseId)
myArr = [eventID, location, eventDate, raceNum, raceID, saddle,
horse, horseId, barrier, career, age, description, weights]
raceFields.append(myArr)
print(raceFields)
目前没有回答
相关问题 更多 >
编程相关推荐