当前位置:网站首页>已解决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)
边栏推荐
- JVM -- Analysis of bytecode
- No Identifier specified for entity的解决办法
- Family Trivia
- Your appearance is amazing! Two JSON visualization tools are recommended for use with swagger. It's really fragrant
- hugo学习笔记
- 【英雄哥六月集训】第 25天: 树状数组
- A brief introduction to R language pipeline symbols (% >%) and placeholders (.)
- Metasploit Eternal Blue attack
- kgdb调试内核无法执行断点及kdb-22:Permisson denied
- 【精选】如何完美的写 PHP 代码的呢?
猜你喜欢

Warning: remote head references to nonexistent ref, unable to checkout error messages

TDengine 助力西门子轻量级数字化解决方案 SIMICAS 简化数据处理流程

Matlab底层源代码实现图像的中值滤波(用于消除图像上一些杂点)

How to smooth the online and offline of Web Services

gyp ERR! configure error. gyp ERR! stack Error: gyp failed with exit code: 1

ctf (hardrce)

文档智能多模态预训练模型LayoutLMv3:兼具通用性与优越性

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

Data types and variables

samba服务器
随机推荐
samba服务器
Understanding and code implementation of Se (sequence and exception) module
搭建 Samba 服务
No Identifier specified for entity的解决办法
Sound processing - Mel frequency cepstrum coefficient (MFCC)
PHP generates text and image watermarks
[brother hero July training] day 16: queue
Matlab- draw date and duration diagram
Oracle view hard parsing
【Flutter】SharedPreferences使用
[brother hero June training] day 25: tree array
[brother hero's June training] day 27: picture
Voice data acquisition - real time voice data visualization
Hugo learning notes
wind10配置adb命令
Key points of ES6 class inheritance
[brother hero June training] day 28: dynamic planning
warning: remote HEAD refers to nonexistent ref, unable to checkout报错信息
Multipoint bidirectional republication and routing strategy
异构计算技术分析