在最底层实现访问文件的方法里获取根目录,然后拼接目标文件目录,需要访问的传入文件名即可
例如:
import os
base_dir = str(os.path.dirname(os.path.dirname(__file__)))
base_path = base_dir+'/resource/'
def test(filename="test.xlsx")
filepath = base_path+filename
try:
file = xlrd.open_workbook(filepath)
sheet=file.sheet_by_index(sheet)
data = sheet.cell(row,col)
return data
except Exception as e:
print(e)