我是Python的初学者,所以我试着学习如何打开文件。我写了下面的代码
test_file = open('C:\Users\Harsh\Desktop\Anything\RoR.txt')
text = test_file.read()
print(text)但它给了我这个错误
File "C:\Users\Harsh\Desktop\CODING\Python\testing.py", line 1
test_file = open('C:\Users\Harsh\Desktop\Anything\RoR.txt')
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape发布于 2021-03-14 13:23:32
尝试添加“编码”,“r”表示原始文本
test_file = open(r"C:\folder\file.txt",encoding='utf8')https://stackoverflow.com/questions/66624962
复制相似问题