Error with back slash in python open statement

喜欢而已 提交于 2021-01-29 10:49:25

问题


Is there any way without typing r or 'double slash' to resolve this problem.because this two tricks change the type of file:

f = open('C:\Users\alireza\Desktop\exersices.python\p5.files\1.txt')

Error:

File "<ipython-input-1-243f8d6a931c>", line 1
    f = open('C:\Users\alireza\Desktop\exersices.python\p5.files\1.txt')
            ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

回答1:


This will solve your issue.

f = open('C:/Users/alireza/Desktop/exersices.python/p5.files/1.txt')


来源:https://stackoverflow.com/questions/52243287/error-with-back-slash-in-python-open-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!