当前位置:网站首页>已解决SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated
已解决SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated
2022-07-27 10:16:00 【无 羡ღ】
已解决SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated
报错代码
一个粉丝群里的小伙伴提出的问题(xlrd库读取Excel表格报错):

然后我把他的代码复制过来看了一下就明白为啥了:
import xlrd
wb = xlrd.open_workbook("C:\Users\Administrator\Desktop\./TEST.xlsx")
print(wb)
报错信息:

File "E:/Python学习/2.py", line 2
wb = xlrd.open_workbook("C:\Users\Administrator\Desktop\./TEST.xlsx")
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
报错翻译
报错内容翻译:
语法错误:(unicode错误)“UnicodeScape”编解码器无法解码位置2-3中的字节:截断\uxxxxxxx转义
报错原因
报错原因:在Python中 \ 是转义符,\u表示其后是UNICODE编码,因此\User在这里会报错。
解决方法
解决方法1:在字符串前面加个 r(rawstring 原生字符串),可以避免python与正则表达式语法的冲突!
import xlrd
wb = xlrd.open_workbook(r"C:\Users\Administrator\Desktop\./TEST.xlsx")
print(wb)
解决方法2:每个\前面再加个\表示转义,斜杠就能正常表示了
import xlrd
wb = xlrd.open_workbook("C:\\Users\\Administrator\\Desktop\\./TEST.xlsx")
print(wb)
边栏推荐
- [brother hero June training] day 23: dictionary tree
- It is thought-provoking: is syntax really important? Qiu Xipeng group proposed a powerful baseline for aspect based emotional analysis
- Basic statement of database operation
- PHP generates text and image watermarks
- ctf (hardrce)
- Two architectures of ETL (ETL architecture and ELT Architecture)
- Understanding and code implementation of Se (sequence and exception) module
- 数据库操作基础语句
- JVM -- Analysis of bytecode
- 【Liunx】安装Redis
猜你喜欢

Custom page 01 of JSP custom tag

Matlab low-level source code realizes the median filtering of the image (used to eliminate some miscellaneous points on the image)

Understanding and code implementation of Se (sequence and exception) module

服务器访问速度

Beijing publicized the spot check of 8 batches of children's shoes, and qierte was listed as unqualified

MySQL数据表的高级操作

MySQL log management, backup and recovery

Mail server

数据库操作基础语句

JVM -- Analysis of bytecode
随机推荐
warning: remote HEAD refers to nonexistent ref, unable to checkout报错信息
Matlab-创建 MATLAB的logo
【英雄哥六月集训】第 24天: 线段树
sql注入
【Flutter】SharedPreferences使用
Different binary conversion of MATLAB
Matlab discrete event system simulation experiment
Sub query of database performance series
声音处理之-梅尔频率倒谱系数(MFCC)
wind10配置adb命令
It is thought-provoking: is syntax really important? Qiu Xipeng group proposed a powerful baseline for aspect based emotional analysis
JSP自定义标签之自定义分页01
Oracle查看硬解析
Eslint的报错信息Module Error (from ./node_modules/[email protected]@eslint-loader/index.js)解决方法
【英雄哥六月集训】第 26天: 并查集
Matlab sound classification based on short-time neural network
Matlab/simulink sample sharing for solving differential equations
TDengine 商业生态合作伙伴招募开启
MySQL deadlock, pessimistic lock, optimistic lock
【英雄哥六月集训】第 27天: 图