这是一个示例:
高分.txt
1,2
5,5
6,2
4,3
5,2
# we are creating a file handle here inorder to read file.
highscorefile = open('highscores.txt','r')
# We are reading the file contents using the read function
cont = highscorefile.read()
# we are splitting the read content line by line and \n represents new lines here
for line in cont.split('\n'):
# we are again splitting the line by commas and address first item for dice1, second time for dice two and converting them to integers and addressing for the sum
print(" dice1 : ",line.split(',')[0]," dice2 : ",line.split(',')[1]," sum : ",int(line.split(',')[0]) + int(line.split(',')[2])
#After completing this operations we are closing the file.
highscorefile.close()