python 不同方式读取文件速度不同的实例
1、按行读取较慢较耗时:
srcFiles=open('inputFile.txt','r') forfile_pathinsrcFiles: file_path=file_path.rstrip()
2、快速读取所有行:
withopen('inputFile.txt','r')asfRead: srcPaths=fRead.readlines()#txt中所有字符串读入list列表srcPaths random.shuffle(srcPaths)#打乱list顺序 forimg_pathinsrcPaths: img_path=img_path.rstrip()
以上这篇python不同方式读取文件速度不同的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。