0

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
hbaderts
  • 14,136
  • 4
  • 41
  • 48
  • please do not post pictures of errors. Edit the post and post the error and the code causing it. See [this](http://idownvotedbecau.se/imageofanexception/) for more information. – Francesco Montesano Apr 30 '18 at 11:41
  • 1
    Possible duplicate of [Why do I get a SyntaxError for a Unicode escape in my file path?](https://stackoverflow.com/questions/18084554/why-do-i-get-a-syntaxerror-for-a-unicode-escape-in-my-file-path) – hbaderts Apr 30 '18 at 11:52

2 Answers2

1

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.

Syn
  • 776
  • 12
  • 30
1

You would have to duplicate all of the backslashes