欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python 逐行读取txt文件

程序员文章站 2022-03-25 22:26:14
逐行读取txt文件 path = r'D:\123456\1.txt'with open(path, 'r', encoding='utf-8') as f: for line in f: value = line[:-1] #去掉换行符 print(value) ......

逐行读取txt文件

path = r'd:\123456\1.txt'
with open(path, 'r', encoding='utf-8') as f:
    for line in f:
        value = line[:-1] #去掉换行符
        print(value)