运行python文件时路径错误
传入的文件路径为"C:\Users\19168\Desktop\data.txt 但运行的时候显示
SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
原因是在python中 \有转义的含义 所以可以用如下方法
①绝对路径 :\代替\ “C:\Users\19168\Desktop\data.txt”
②使用linux路径表示方法:/代替\ “C:/Users/19168/Desktop/data.txt”
③声明字符不用转义:路径前加r r"C:\Users\19168\Desktop\data.txt"