龙空技术网

python读取文件

爱拼才会赢的Jack 100

前言:

眼前小伙伴们对“python按行读取文件 with open”可能比较珍视,大家都需要剖析一些“python按行读取文件 with open”的相关知识。那么小编也在网络上网罗了一些有关“python按行读取文件 with open””的相关内容,希望你们能喜欢,小伙伴们一起来了解一下吧!

python批量读取文件,一行一行输出并去除换号符

输出字符串数据类型

import syswith open("test.log", 'r', encoding='utf-8') as f:    while True:        rsize = 1024*1024*1                                 #每次读取1M大小        lines = f.readlines(rsize)        if not lines:           break        for line in lines:            message = line.replace("\n", "")                           print(message)

python一行一行读取文件,一行一行输出并去除换号符

输出列表数据类型

with open('test.log', 'r', encoding = 'utf-8') as f:    while True:        line = f.readline()         if not line:             break        message = line.split('\n')        print(message)

标签: #python按行读取文件 with open