![图片[1]-python3过大数据如何读取?-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5ed0a3885a56f833.jpg)
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原文来自:https://www.py.cn
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END


















































暂无评论内容