SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated \UX

读取文件时出现:
SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
错误,原因是因为转义字符的问题,如果是这样写的

with open('C:\Users\Administrator\Desktop\数据库\勾号.png', 'rb') as f:
	pass

需要加上r‘’变成元字符或者直接使用反斜杠

with open(r'C:\Users\Administrator\Desktop\数据库\勾号.png', 'rb') as f:
或者是
with open('C:/Users/Administrator/Desktop/数据库/勾号.png', 'rb') as f:

你可能感兴趣的:(读取文件路径问题)