python open语句中的反斜杠出错

问题描述 投票:0回答:1

有没有办法没有键入r或'双斜杠'来解决这个问题。因为这两个技巧改变了文件的类型:

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

错误:

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
python string windows syntax-error filepath
1个回答
1
投票

这将解决您的问题。

f = open('C:/Users/alireza/Desktop/exersices.python/p5.files/1.txt')
© www.soinside.com 2019 - 2024. All rights reserved.