【发布时间】:2017-01-29 12:03:54
【问题描述】:
我正在尝试遍历仅包含 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'
有办法解决吗?
【问题讨论】:
-
文件夹应该只包含 xls 文件。带有任何扩展名的文件
002_Testo都可能导致错误,因为-我猜-xlrd.open_workbook(file)将.xls扩展名添加到file。 -
有这样的文件吗?
标签: python excel python-2.7 path xls