我正在尝试使用该库组织大量.DTA
文件。xlrd
我发现的第一件事是,只需更改扩展名 .xls 并在 excel 中打开它们,就可以将 .DTA 文件导出为 excel 文件。当您打开它时会发出警告,它会给出有关文件可能已损坏的错误,但否则会正常打开。
the file you are trying to open is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
然而,在 python 中,当我尝试打开文件时,我得到的只是一个没有有用信息的错误,我很确定这是由文件扩展名问题引起的。
File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 1323, in getbof
raise XLRDError('Expected BOF record; found 0x%04x' % opcode)
XLRDError: Expected BOF record; found 0x5845
我通过将数据剪切并粘贴到一个新的 excel 文件中并将其命名为相同的东西来尝试我的代码,并且它有效,所以我很确定这是问题所在,但我有太多文件无法为每个文件执行此操作一个人。
有没有更好的方法来解决这个问题?抑制错误或实际更改文件类型而不仅仅是它的扩展名?