问答详情
源自:3-2 xlrd常用函数

运行报错提示

import xlrd
d1 = xlrd.open_workbook('dat1.xlsx')
print(d1.sheet_loaded(0))
d2 = xlrd.open_workbook("C:\Users\wangming\Desktop\dat2.xlsx")
print(d2.sheet_loaded(0))

运行结果

"F:\Program Files (x86)\python\python.exe" E:/python实操/index.py

  File "E:/python实操/index.py", line 4

    d2 = xlrd.open_workbook("C:\Users\wangming\Desktop\dat2.xlsx")

                           ^

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape


提问者:慕姐7583652 2021-11-05 15:46

个回答

  • W_H_Y
    2021-11-11 17:19:58


    import xlrd
    d1 = xlrd.open_workbook('dat1.xlsx')
    print(d1.sheet_loaded(0))
    d2 = xlrd.open_workbook("C:\Users\wangming\Desktop\dat2.xlsx")
    print(d2.sheet_loaded(0))


    把第4行中的路径,从反斜杠转换成正斜杠。

    "C:\Users\wangming\Desktop\dat2.xlsx" 换成 "C:/Users/wangming/Desktop/dat2.xlsx"

    还有就是xlrd开不了Excel xlsx 的文件