我正在尝试解析文本文件中的项目并将它们存储到列表中。数据看起来像这样:
[(0, 0, 0), (1, 0, 0), (2, 0, 0), (3, 0, 0), (4, 0, 0), (5, 0, 0), (6, 0, 0)]
[(10, 3, 1), (11, 3, 1), (12, 3, 1), (13, 3, 1), (13, 4, 1)]
[(10, 3, 5), (11, 3, 5), (12, 3, 5), (13, 3, 5), (13, 4, 5), (13, 5, 5), (13, 6, 5)]
[(6, 13, 5), (7, 13, 5), (8, 13, 5), (8, 14, 5), (7, 14, 5), (6, 14, 5), (6, 14, 6)]
我能够剥离“[”和“]”,但无法将其余信息以如下格式存储到列表中:(x, y, z)。有什么帮助吗?
def dataParser(fileName):
zoneList=[]; zone=[]
input=open(fileName,"r")
for line in input:
vals = line.strip("[")
newVals = vals.strip("]\n")
print newVals
v=newVals[0:9]
zone.append(v)
input.close()
return zone