-2
file = open("SampleList.txt", "r")
x = file.readlines()
y = []
for i in range (len(x)):
print x[i].split()
这是我的代码,这是输出需要提出的“”,工作
['100000,Weasely', ',Bill', ',9,1', 'Discipline,0']
['120001,Weasely', ',Fred', ',10,1', 'Discipline,0']
['120002,Weasley', ',George', ',6,1', 'Tardies,0']
['130003,Weasley', ',Ronald', ',10,OK,0']
['130004,Longbottom', ',Neville', ',5,1', 'Absence,0']
['130005,Potter', ',Harry', ',5,OK,0']
['130006,MAlfoy', ',Draco', ',5,1', 'Owes', 'more', 'than', '$5,$150.00']
['100118,The', 'House', 'Elf', ',Dobbey', ',7,OK,0']
['100011,LaStrange', ',Belatrix', ',8,1', 'Discipline,0']
['100170,Dumbledore', ',Albus', ',7,1', 'Administration,0']
>>>
我需要的是[“数”,“姓氏”,“名” ,等等]
为什么不''x [i] .split(',')' – The6thSense
你目前正在分割空白。如果这不是你想要的,*拆分别的东西*。另外,请注意''csv'库正是这种事情。 – jonrsharpe