Reputation: 311
I am trying to use the XLRD library in IronPython 2.7
At the most basic operation of opening an .xls file (2003 format) I get the following error, and I am not sure how to fix it:
workbook = xlrd.open_workbook(xlsfile)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\xlrd\__init__.py", line 426, in open_workbook
TypeError: sequence item 0: expected bytes or byte array, str found
any ideas? i would like to use xlrd if possible but seems like there may be some compatibility problems. When using Python 2.7 interpreter the file opens no problem ..
Upvotes: 2
Views: 1836
Reputation: 455
I am trying to add xlrd to ironpython 2.7 in CODESYS and run into same problem. However, after trying version 0.8.0 it works fine.
Upvotes: -1
Reputation: 3477
I fought with this for some time in xlrd 0.9.2. Neither bytes
, bytearray
, str
, or even reading the file manually and passing it as file_contents
worked.
Finally I downgraded xlrd to version 0.8.0 and... it's working. :)
Upvotes: 3
Reputation: 7662
For whatever reason it seems that open_workbook
requires the filename to be in bytes, not as a string. Try:
workbook = xlrd.open_workbook(bytes(xlsfile))
That's an issue you're likely to encounter a lot: IronPython's strings are Unicode by default (like Python 3) and not byte strings like Python 2.
Upvotes: 1