有没有办法没有键入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
这将解决您的问题。
f = open('C:/Users/alireza/Desktop/exersices.python/p5.files/1.txt')