fileObj=open("list.txt",mode="r",edcoding="UTF-8")
list=[]
while True:
读取每一行文字内容
name=fileObj.readline()
print(name)
如果为空则不再继续读取
if name=="":
break
else:# 把读取到的姓名添加到列表中
list.append(name)
输出列表内容
print(list)
释放资源
fileObj.close()
2023-12-02 15:26:40
fileObj=open("list.txt",mode="r",edcoding="UTF-8")
list=[]
while True:
name=fileObj.readline()
print(name)
if name=="":
break
else:# 把读取到的姓名添加到列表中
list.append(name)
print(list)
fileObj.close()