python超速遍历文件夹下面三十几万个txt文档的处理,,1.文件夹下面有三十几万


1.文件夹下面有三十几万txt文档。
2.如下代码感觉太慢

fp = open("texts.txt","a+")for root,dirs,files in os.walk(dir):    for file in files:        fp.write(file+'\n')        print os.path.join(root,file)fp.close()    

3.有没有其他方法快速遍历

你遍历以后要干啥呢?如果简单的查找替换啥的,用grep/sed啊

试试 Python 3.5 或以上的版本。

[this version] makes it [os.walk / os.scandir] 3 to 5 times faster on POSIX systems and 7 to 20 times faster on Windows systems

有计算吗?没计算多线程或者协程来做

编橙之家文章,

评论关闭