2020-10-31
阅读量:
673
Python 读取文件的几种方法
# 1f = open('fileName', 'r')# do something with ff.close()# 2with open('fileName', 'r') as f:# do something with f# no need to close, and will close automatically if exception rised
lines = f.readlines()for line in lines:fun(line)
for line in f:fun(f)
line = f.readline()while line:fun(line, f) # can read more line by f.readline()line = f.readline()






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论