我有一个简单的程序,它带有一个ID号,并为匹配ID的人打印信息.信息存储在.dat文件中,每行一个ID号.
问题是我的程序也在从文件中读取换行符\n.我尝试了'name'.split()方法,但这似乎不适用于列表.
我的节目:
from time import localtime, strftime
files = open("grades.dat")
request = open("requests.dat", "w")
lists = files.readlines()
grades = []
for i in range(len(lists)):
grades.append(lists[i].split(","))
cont = "y"
while cont == "y" or cont == "Y":
answer = raw_input("Please enter the Student I.D. of whom you are looking: ")
for i in range(len(grades)):
if answer == grades[i][0]:
print grades[i][1] + ", " + grades[i][2] + (" "*6) + grades[i][0] + (" "*6) + grades[i][3]
time = strftime("%a, %b %d …Run Code Online (Sandbox Code Playgroud)