python 文件操作——读入文件内容的方法

读入文件中空格分隔的数字,存入列表

with open("duru.txt","r") as file:
a=file.read()
b=[int(i) for i in a.split()]
print(b)

读入文件中每行显示的数字,存入列表

with open("duru2.txt","r") as file:
a=file.read()
c=[int(i) for i in a.split()]
print(c)

发表回复