当我从另一个文件导入函数时,它显示ImportError异常 当我将holiday_collection()函数导入到check_sunday_holiday()函数时,我的第一个文件有一个名为check_sunday_holiday()的函数,第二个函数有一个holiday_collection(),它显示了Import ImportError代码
第一个文件数据库
import reportcfg as cfg
import pyodbc
from datetime import date, timedelta
from report import check_sunday_holiday
from datetime import datetime
def holiday_collection( ):
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER='+cfg.server_database['server_name']+';DATABASE=' + cfg.server_database['database_name'])
cursor = cnxn.cursor()
cursor.execute("select StartDate from gnMstPublicHoliday ")
START=[ x[0] for x in cursor.fetchall()]
m=str(datetime.now().date())
for i in range(0,len(START)):
#print(START[i])
if START[i]==m:
print("Date found ")
cursor.execute("select EndDate from gnMstPublicHoliday ")
END=[ x[0] for x in cursor.fetchall()]
print(END)
cursor.execute("select LeaveDays from gnMstPublicHoliday ")
LEAVE=[ x[0] for x in cursor.fetchall()]
print(LEAVE)
check_sunday_holiday(START,END,LEAVE)
第二份文件报告
import Database
def check_sunday_holiday(START,END,LEAVE):
global Date_minz
发生了异常:ImportError
无法从“报告”中导入名称“ check_sunday_holiday”