"""对student.txt进行操作"""
with open("student.txt", 'r+', encoding='utf8') as file:
content = file.readlines() # 哈哈,没想到吧,这是个多维列表!
i = 0
for line in content[1:]: # 从第2行开始记录
wordList = line.strip().split() # 将lineStr默认切割(分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等)
print(wordList)
sum = 0
if wordList != []:
for word in wordList[1:]:
sum += eval(word)
filename = "new.txt"
i+=1
with open(filename, 'a+', encoding='utf8') as f:
f.write("{}\t{}\n".format(wordList[0], sum))
print(sum)