import xlrd
date=xlrd.open_workbook('D:\Users\JCDN\Desktop\auto_case\case.xlsx') #打开文件
table=date.sheet_by_name('3020') #获取sheet页
在读取桌面文件的时候一直报错:(unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
后来发现,在Python中\是转义符,\u表示其后是UNICODE编码,因此\User在这里会报错,在字符串前面加个r表示就可以了
import xlrd
date=xlrd.open_workbook(r'D:\Users\JCDN\Desktop\auto_case\case.xlsx') #打开文件,r的作用是禁止字符串转义
table=date.sheet_by_name('3020') #获取sheet页