Python 2.7 复制太慢了
我有几千个excel文件已经有好几年了。所有文件的名称中均包含年份,如2010年、2011年等。excel文件中的某些部分包含诸如关闭、工作表中的关闭之类的关键字。这些关键词可能出现在一句话中,例如因施工而导致的道路封闭。我想写一个代码,这样我就可以复制特定年份的文件,而这些文件的工作表中没有这些关键字。以下代码正在运行,但速度太慢。有没有办法加快速度Python 2.7 复制太慢了,python-2.7,xlrd,shutil,Python 2.7,Xlrd,Shutil,我有几千个excel文件已经有好几年了。所有文件的名称中均包含年份,如2010年、2011年等。excel文件中的某些部分包含诸如关闭、工作表中的关闭之类的关键字。这些关键词可能出现在一句话中,例如因施工而导致的道路封闭。我想写一个代码,这样我就可以复制特定年份的文件,而这些文件的工作表中没有这些关键字。以下代码正在运行,但速度太慢。有没有办法加快速度 import glob import os import shutil import xlrd os.chdir("G:/_Traffic Co
import glob
import os
import shutil
import xlrd
os.chdir("G:/_Traffic Counts/Traffic Volumes/")
choice = raw_input("Specify the Year to Copy (e.g. 2012) and Press Enter ")
location = ("C:/Users/tsengineer/Desktop/Trial_JM/")
notcopy = ("closure", "Closure")
i = 0
for file in glob.glob("*.xls"):
if choice in file:
book = xlrd.open_workbook(file)
sheet = book.sheet_by_index(0)
for row in range(sheet.nrows):
for column in range(sheet.ncols):
if any(s in str(sheet.cell(row,column).value) for s in notcopy):
pass
else:
shutil.copy(file, location)
print "Copying...", i+1
i = i + 1
print "Copying Complete. Total File Copied:", i
知道哪里慢吗?复制要花很长时间。运行时间真的很长。循环有什么问题吗?是吗?不,我不知道出了什么问题,因为我没有费心分析。?