SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UX
程序员文章站
2022-06-15 13:50:23
...
D:\code\draw_path\venv\Scripts\python.exe D:/code/draw_path/dispaly_pic/draw_pic_2.py
File "D:/code/draw_path/dispaly_pic/draw_pic_2.py", line 9
plt.savefig("C:\Users\octopus\Desktop\html")
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
python出现报错问题:应该是转义字符有错,在前面加上r代表原来意思就没有出现这种错误了。
# encoding='utf-8'
import matplotlib.pyplot as plt
import numpy as np
x=np.arange(0,10,0.2)
y=np.sin(x)
fig,ax=plt.subplots()
ax.plot(x,y)
plt.savefig("C:\Users\octopus\Desktop\html")
plt.show()
应该改为:
# encoding='utf-8'
import matplotlib.pyplot as plt
import numpy as np
x=np.arange(0,10,0.2)
y=np.sin(x)
fig,ax=plt.subplots()
ax.plot(x,y)
plt.savefig(r"C:\Users\octopus\Desktop\html")
plt.show()
上一篇: MNN Interpreter and Session
下一篇: 函数相关注意事项
推荐阅读
-
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
-
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 \UX
-
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 \UX
-
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 \UX
-
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 \UX