python-读取txt文本

import tensorflow as tf
import os

with open('test_read.txt', 'r') as file:
    lines = file.readlines()
    nlines = len(lines)
    for i, text in enumerate(lines):
        print(i,text)

  

原文

dao ke dao
fei chang dao
ming ke ming
fei chang ming

laozi
2018.09.10

  

输出结果

0 dao ke dao

1 fei chang dao

2 ming ke ming

3 fei chang ming

4

5 laozi

6 2018.09.10

7

8

  

 

posted @ 2018-09-10 10:04  路边的十元钱硬币  阅读(174)  评论(0编辑  收藏  举报