通过网络共享读取Python中的Excel文件非常慢
我正在使用xlrd库和Python通过UNC网络共享读取大约200个小Excel文件。打开Excel文件的过程非常缓慢。我制作了一个简单的基准测试程序来测量只打开Excel文件而不做任何其他事情所需的时间 计时器报告读取100个大小为50KB的Excel文件需要92秒。为什么要花这么长的时间?通过无线连接访问同一网络共享,几乎需要2-3分钟 最后,我需要保存Excel工作簿中的一些数据,然后用收集到的信息编写一个新的Excel文件。我是不是做错了什么,让事情变得更糟了通过网络共享读取Python中的Excel文件非常慢,excel,performance,python-2.7,xlrd,Excel,Performance,Python 2.7,Xlrd,我正在使用xlrd库和Python通过UNC网络共享读取大约200个小Excel文件。打开Excel文件的过程非常缓慢。我制作了一个简单的基准测试程序来测量只打开Excel文件而不做任何其他事情所需的时间 计时器报告读取100个大小为50KB的Excel文件需要92秒。为什么要花这么长的时间?通过无线连接访问同一网络共享,几乎需要2-3分钟 最后,我需要保存Excel工作簿中的一些数据,然后用收集到的信息编写一个新的Excel文件。我是不是做错了什么,让事情变得更糟了 import time i
import time
import sys
import os
import re
from xlrd import open_workbook,cellname, XLRDError
from xlwt import Workbook
from timeit import default_timer as timer
def ReadReports():
start = timer()
filename_pattern = re.compile('^Report_name_.*')
count =0
root_directory = r'//network/path/somedirectory'
for path, dirs, files in os.walk(root_directory):
files[:] = [f for f in files if re.match(filename_pattern,f)]
for file in files:
count+=1
try:
#get the input file object (open the excel workbook)
fullpath = os.path.join(path,file)
book = open_workbook(fullpath)
except IOError:
logger.exception('Program encountered IOError')
continue
except XLRDError as e:
logger.exception('Program encountered XLRDError')
continue
else:
pass
print "num files: ", count
end = timer()
print "time: %r seconds" %(end - start)
if __name__ == "__main__":
ReadReports()
我也有同样的问题,以下是一些你可以尝试的东西:
我的问题有什么不清楚的地方吗?有人能帮我吗?