【发布时间】:2018-10-23 07:02:04
【问题描述】:
我在.txt 文件中有此表单的列表:student1, 2, 3 | student2, 1, 4
我需要在程序中调用它,将[student3, 3, 5] 添加到列表中,然后将其保存回.txt 文件中。我这样做了,但我的列表最后看起来像这样:[[''], ['Student3', '3', '5']]
f = open('classe1.txt','r')
liste = f.read()
liste = liste.split('|')
n = len(liste)
for i in range (n):
liste[i] = liste[i].split(',')
liste.append(['Student3','3','5'])
liste = str(liste)
f = open('classe1.txt','w')
f.write(liste)
你会怎么做? 谢谢!
【问题讨论】:
-
请发布一个实际的txt文件样本和想要的结果。
-
学生 1、2、3 |学生2、1、4
-
我试着写了 [[student1, 2, 3], [student2, 1, 4]] 原来
-
你想要的输出应该是什么样子?
-
最终的txt文件需要什么。