当前位置:网站首页>已解决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)
边栏推荐
- 【Flink】Flink进行Standalone模式的集群搭建
- No Identifier specified for entity的解决办法
- Matlab- draw bifurcation and chaotic bifurcation diagrams
- Analysis of heterogeneous computing technology
- Establishment of NFS server
- 【英雄哥六月集训】第 27天: 图
- MySQL log management, backup and recovery
- 服务器访问速度
- Mysql死锁、悲观锁、乐观锁
- 文档智能多模态预训练模型LayoutLMv3:兼具通用性与优越性
猜你喜欢
![[Flink] Flink builds clusters in standalone mode](/img/5b/e566fdd2792b5cda7d37d308ee32e2.png)
[Flink] Flink builds clusters in standalone mode

How to turn off the application of computer self startup

让人深思:句法真的重要吗?邱锡鹏组提出一种基于Aspect的情感分析的强大基线...
[email protected]@eslint-loader/index.js)解决方法"/>Eslint的报错信息Module Error (from ./node_modules/[email protected]@eslint-loader/index.js)解决方法

Based on LSM tree idea Net 6.0 C # write a kV database (case version)

flask_ Output fields in restful (resources, fields, marshal, marshal_with)

Server access speed

【Flink】Flink进行Standalone模式的集群搭建

ctf (hardrce)

Two architectures of ETL (ETL architecture and ELT Architecture)
随机推荐
File upload vulnerability bypass method
Hugo learning notes
Apache cannot start in phpstudy
TDengine 商业生态合作伙伴招募开启
gyp ERR! configure error. gyp ERR! stack Error: gyp failed with exit code: 1
Eslint的报错信息Module Error (from ./node_modules/[email protected]@eslint-loader/index.js)解决方法
NodeJS中Error: getaddrinfo ENOTFOUND localhost
Matlab- draw bifurcation and chaotic bifurcation diagrams
Your appearance is amazing! Two JSON visualization tools are recommended for use with swagger. It's really fragrant
想要一键加速ViT模型?试试这个开源工具!
R语言管道符(%>%)及占位(.)的简单介绍
【英雄哥六月集训】第 28天: 动态规划
【英雄哥六月集训】第 27天: 图
Establishment of NFS server
Two architectures of ETL (ETL architecture and ELT Architecture)
免费 DIY 之旅问题
es6的foreach与some的循环遍历
【Liunx】安装Redis
多点双向重发布和路由策略
Understanding and code implementation of Se (sequence and exception) module