简体   繁体   中英

SyntaxError (unicode error) when trying to read Matlab file in Python

I am trying to read a Matlab file in Python, but it gives an error. Can anyone help me out?

I run the following code:

from scipy.io import loadmat
data = loadmat('C:\Users\Sakraan\Desktop\stomachpain.mat')

but I get the following error:

data = loadmat('C:\Users\Sakraan\Desktop\stomachpain.mat')
                ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in
position 2-3: truncated \UXXXXXXXX escape

The \\U from your path relating to C:\\Users... is an Unicode escape. In order to get your path to work you would have to duplicate all of the backslashes.

你必须复制所有的反斜杠

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM