当前位置:网站首页>已解决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)
边栏推荐
- sql注入
- Matlab/simulink sample sharing for solving differential equations
- phpstudy中Apache无法启动
- [Flink] Flink builds clusters in standalone mode
- Beijing publicized the spot check of 8 batches of children's shoes, and qierte was listed as unqualified
- gyp ERR! configure error. gyp ERR! stack Error: gyp failed with exit code: 1
- Set up Samba service
- Share machine learning notes (PDF version) + practical projects (dataset + code)
- [Linux] mariadb/mysql scheduled full backup script and data recovery
- ctf (hardrce)
猜你喜欢

Data types and variables

Server access speed

数据类型与变量

【Flutter】SharedPreferences使用

It is thought-provoking: is syntax really important? Qiu Xipeng group proposed a powerful baseline for aspect based emotional analysis

全校软硬件基础设施一站式监控 ,苏州大学以时序数据库替换 PostgreSQL

It is thought-provoking: is syntax really important? Qiu Xipeng group proposed a powerful baseline for aspect based emotional analysis

Set up Samba service

wind10配置adb命令

No Identifier specified for entity的解决办法
随机推荐
简单几步教您实现为工业树莓派共享网络
jvm--字节码浅析
PHP generates text and image watermarks
NodeJS中Error: getaddrinfo ENOTFOUND localhost
How to smooth the online and offline of Web Services
Analysis of heterogeneous computing technology
[brother hero July training] day 16: queue
【英雄哥六月集训】第 24天: 线段树
[Linux] install redis
Alibaba mailbox web login turn processing
It is thought-provoking: is syntax really important? Qiu Xipeng group proposed a powerful baseline for aspect based emotional analysis
数据类型与变量
es6 class 继承的重点
Data types and variables
TDengine 助力西门子轻量级数字化解决方案 SIMICAS 简化数据处理流程
基于Spark封装的二次开发工程edata-base,介绍
Voice data acquisition - real time voice data visualization
Local connection to remote server database under Windows platform (I)
Ubuntu及Mysql快速入门教程
Family Trivia