Python 没有这样的文件或目录
我试图遍历一个只包含xls文件的文件夹并逐个打开它们。 注意:所有的xsl文件都被列举为“001_text.xls”,…“030_text.xls”。
我的代码是:
xls_path=r'C:\path\to\my\folder' for file in os.listdir(xls_path): book = xlrd.open_workbook(file) sheet = book.sheet_by_index(0) filt_xls = [ el for el in sheet.col_values(0)] print file.title() print filt_xls
问题是,我只得到第一个文件(001_text.xls)的输出,并连续出现错误:
IOError: [Errno 2] No such file or directory: '002_Testo.xls'
有没有办法解决它?
您可能已经忘记为每个文件path添加一个目录名称
import os.path for file in os.listdir(xls_path): file = os.path.join(xls_path, file) .....