迭代大型txt文件需要多长时间? / Python

时间:2015-04-27 15:33:24

标签: python performance file iterator

下面的代码用于迭代一些大的.txts。

迭代80MB文件10分钟:这是我应该期待的吗?我的做法是否存在根本性的错误?

print 'File size = ' + str(os.path.getsize(FullPath))
print time.gmtime()
with open(FullPath) as FileObj:
    for lines in FileObj:
        i +=1
print i
print time.gmtime()

输出:

File size = 80536606
time.struct_time(tm_year=2015, tm_mon=4, tm_mday=27, tm_hour=15, tm_min=16, tm_sec=6, tm_wday=0, tm_yday=117, tm_isdst=0)
140614
time.struct_time(tm_year=2015, tm_mon=4, tm_mday=27, tm_hour=15, tm_min=26, tm_sec=21, tm_wday=0, tm_yday=117, tm_isdst=0)

基于这些链接的代码:

How to read large file, line by line in python

Looping through big files takes hours in Python

0 个答案:

没有答案