[英]How can I delete the Read files after --->>(for root, dirs, files in os.walk()) <<— with function os.remove() in python
[英]seaching all excel files with os.walk (), then call the function to read this excel, How can I do it?
我創建了一個讀取Excel工作表read_Excel_file(path)的函數,該函數返回一個列表,其中包含來自特定列的一些數據。
然后在主代碼中搜索所有excel文件(名稱以Design開頭),並且此excel文件應保存在Design
文件夾中。 如果找到excel文件,則調用函數read_Excel_file
。
請在下面的代碼中找到:
import openpyxl as opx
import os
for r, d, f in os.walk('.'):
for file in f:
if '.xlsx' and 'design' in file:
#print(r)
if r.endswith('\Design'):
print(file)
read_Excel_file(file)
但我得到了錯誤:
無此文件或目錄
即使我確定我的目錄中有此文件
你認為我有路徑問題嗎?
PS:我添加print(file)
只是為了檢查print(file)
的名稱,但是當read_Excel_file(file)
之后的read_Excel_file(file)
出現錯誤時。
你能幫我嗎?
文件只是文件名。 您缺少完整的地址。 您需要添加地址的根部分。
做就是了:
filepath = os.path.join(r, file)
read_Excel_file(filepath)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.