2
回答
“Unicode Error ”unicodeescape" codec can't decode bytes in position 2-3:truncated UXXXXXXXX escape
华为云数据库免费试用   
#coding=utf-8
import xlrd
def print_xls(path):
    data=xlrd.open_workbook(path)
    table=data.sheets()[1]
    nrows=table.nrows
    books=[]
    for i in range(nrows):
        ss=table.row_values(i)
    for i in range(len(ss)):
        print("+++++++++")
if __name__ == '__main__':
    print_xls("C:\Users\Administrator\Desktop\2014.xls")

这个脚本的功能是将Excel表打印出来

报错显示: “Unicode Error ”unicodeescape" codec can't decode bytes  in position 2-3:truncated UXXXXXXXX escape

请问是什么原因,要如何改



<无标签>
举报
lin-chang
发帖于4年前 2回/719阅
共有2个答案 最后回答: 4年前

引用来自“gnefil.nil”的评论

C:\\Users\\Administrator\\Desktop\\2014.xls 不解释

改成你这样子之后显示如下:
Traceback (most recent call last):   File "C:\Python33\print_xls.py", line 13, in <module>
    print_xls("C:\\Users\\Administrator\\Desktop\\2014.xls")
  File "C:\Python33\print_xls.py", line 4, in print_xls
    data=xlrd.open_workbook(path)
  File "C:\Python33\lib\site-packages\xlrd\__init__.py", line 394, in open_workbook
    f = open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Administrator\\Desktop\\2014.xls'
顶部