python文件逐行读取

方法1:

with open('1.txt', 'r') as fp:
  for line in fp:
    print(line)

 

方法2:

with open('1.txt', 'r') as fp:
  text = fp.readline()
  while text!='':
    print(text)
    text = fp.readline()

posted @ 2021-03-17 17:22  coffee~  阅读(503)  评论(0编辑  收藏  举报