(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escap

在读取桌面文件的时候一直报错:(unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape

自己刚开始写的是这样的:

import scipy as sp

data = sp.genfromtxt(“C:\Users\Administrator\Desktop\Machine Learning\web_traffic.tsv”,delimiter=”\t”)

后来发现,在Python中\是转义符,\u表示其后是UNICODE编码,因此\User在这里会报错,在字符串前面加个r表示就可以了

import scipy as sp

data = sp.genfromtxt(r”C:\Users\Administrator\Desktop\Machine Learning\web_traffic.tsv”,delimiter=”\t”)

你可能感兴趣的:(python学习)