📜  python 从文本文件中调用一行 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:36.546000             🧑  作者: Mango

代码示例1
# Read text file line by line
filepath = 'text_file.txt'
  with open(filepath) as fp:
   line = fp.readline()
   cnt = 1
   while line:
       print("Line {}: {}".format(cnt, line.strip()))
       line = fp.readline()
       cnt += 1