当前位置: 首页 > 图灵资讯 > 行业资讯> python3过大数据如何读取?

python3过大数据如何读取?

发布时间:2026-01-05 22:25:38

在python中读取大文件的方法:

1、使用yield生成器读取

defreadPart(filePath,size=1024,encoding="utf-8"):
withopen(filePath,"r",encoding=encoding)asf:
whileTrue:
part=f.read(size)
ifpart:
yieldpart
else:
returnNone
filePath=r"filePath"
size=2048#每次读取指定大小的内容到内存
encoding='utf-8'
forpartinreadPart(filePath,size,encoding):
print(part)
#Processingdata

2、用open()自带的方法生成迭代对象,这是一行一行的读取

withopen(filePath)asf:
forlineinf:
print(line)
#Processingdata

更多Python知识请关注Python自学网

相关文章

python3过大数据如何读取?

python3过大数据如何读取?

2026-01-05
python3如何引入模块?

python3如何引入模块?

2026-01-05
python3标识符是什么?

python3标识符是什么?

2026-01-05
python3安装库后不能用怎么解决?

python3安装库后不能用怎么解决?

2026-01-04
python32位和64位有什么区别?

python32位和64位有什么区别?

2026-01-04
python的模块保存在哪?

python的模块保存在哪?

2026-01-04