我有球员名单。我想像这样保存在一个文件中
> John, 10
> Raymond, 20
> Oscar, 15
player_list = [['John', 10], ['Raymond', 20], ['Oscar', 15]]
# player_list.append(['Micheal',9])
# print(player_list)
with open('score_test.txt', 'w') as f:
for item in player_list:
f.write("{},{} \n".format(item[0], item[1]))
然后读取“score_test.txt”文件并按如下方式打印 约翰,10岁,雷蒙德,20岁,奥斯卡,15岁
with open('score_test.txt', 'r') as file:
words = file.read().splitlines()
print(words)
然后附加['Micheal',19],成为[['John',10],'Raymond',20],'Oscar',15],'Micheal',19]]
那是马克 [Raymond',20],'Micheal',19],'Oscar',15],'John',10]]然后再次写入文件。谢谢
我想这可能对你有帮助
相关问题 更多 >
编程相关推荐