我似乎在执行以下 Python Scheduler 任务时遇到问题。我有下面的代码,它具有刷新一组目录中的所有工作簿的功能。我尝试测试代码,仅刷新一个目录,然后再移动到其他目录,并且我收到了标题为错误的错误。有人可以帮忙吗?
import time
import schedule
import win32com.client as win32
import os
OD = 'C:/DirectoryString/'
# Sub Directory
Dir1 = 'STR - Doc/Mer Reps/'
Dir2 = 'UK & IE ST - ICS/DB/'
Dir3 = 'UK & IE ST - Docs/DB/2024/'
Dir4 = 'UK & IE RDF - Docs/Rep/DB/Aut/'
Dir5 = 'STR - Doc/RMS/'
Dir6 = 'STR - Doc/Int DB/'
directory_1 = OD + Dir1
directory_2 = OD + Dir2
directory_3 = OD + Dir3
directory_4 = OD + Dir4
directory_5 = OD + Dir5
directory_6 = OD + Dir6
def excel_update(directory):
for filename in os.listdir(directory):
if filename.endswith('.xlsx') or filename.endswith('.xlsm'):
print(f"{directory} {filename}")
file = filename
xlapp = win32.DispatchEx('Excel.Application')
xlapp.DisplayAlerts = False
xlapp.Visible = True
xlbook = xlapp.Workbooks.Open(directory + file)
xlbook.RefreshAll()
xlbook.Save()
xlbook.Close()
del xlbook
xlapp.Quit()
del xlapp
schedule.every(30).minutes.do(excel_update(directory_2))
while True:
schedule.run_pending()
time.sleep(1)
初始作业运行,但是,当第一次重复时,我收到以下错误。
Traceback (most recent call last):
File "C:\Users\gat_mbr\OneDrive - PurmoGroup\Projects\pythonProject\MerchantReports\LoopFunction.py", line 45, in <module>
schedule.every(30).minutes.do(excel_update(directory_2))
File "C:\Users\gat_mbr\OneDrive - PurmoGroup\Projects\pythonProject\MerchantReports\Lib\site-packages\schedule\__init__.py", line 655, in do
self.job_func = functools.partial(job_func, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: the first argument must be callable
schedule.every(30).minutes.do(excel_update, directory=directory_2))