Python 原始输入和读入数据

Python 原始输入和读入数据,python,Python,我目前拥有的是: f = open("SampleList.txt", "r") x = f.readlines() y = [] for i in range (len(x)): y.append(x[i].rstrip('\n').split(',')) for i in range(len(y)): z = y[i] print z 它的回报是: ['100000', 'Weasely ', 'Bill ', '9', '1 Discipline', '0'] ['1200

我目前拥有的是:

f = open("SampleList.txt", "r")

x = f.readlines()
y = []


for i in range (len(x)):
  y.append(x[i].rstrip('\n').split(','))


for i in range(len(y)):
z = y[i]
print z
它的回报是:

['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']
我需要它做的是让一个学生输入他们的学生ID号,这是第一项“10000”,以此类推。 然后,它需要搜索并确定该数字是否有效,是否找到该数字,打印出学生姓名的首末,以及他们是否合格,这是1个学科,1个延迟,如OK。
任何帮助都将不胜感激

在阅读文件内容时使用词典

字典被键入数据文件中的ID号(拆分后每行的第一项),字典中的每个条目都将包含该行的剩余部分,作为
列表

def student_info(student):
    d = {}
    with open("SampleList.txt", "r") as f:
        x = f.readlines()

    for i in range (len(x)):
        ln = x[i].rstrip('\n').split(',')
        # Add this ID to the dictionary keys, and add the remainder of the line as the value for that key
        d[ln[0]] = ln[1:] 

    if student in d:
        return(d[student][1] + ' ' + d[student][0] + ' ' + d[student][-2])
    else:
        return 'invalid student id#'

studentID = raw_input('Enter your student ID#:  ')
print student_info(studentID)

多比的名字里没有e…当我们讨论名字时,是贝拉特里克斯·莱斯特兰奇。提示:y中z的
是什么:打印z[0]
打印?