-2

I have been trying to unpickle this data for a while but running into problems

with open ('C:\Users\chhav\OneDrive\Desktop\mnist.pkl','rb') as f:
   mnist_data = pickle.load(f)

It gives this error:

File "<ipython-input-23-1ef4f2f69776>", line 1
with open ('C:\Users\chhav\OneDrive\Desktop\mnist.pkl','rb') as f:
          ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated 
\UXXXXXXXX escape
miile7
  • 2,547
  • 3
  • 23
  • 38
  • try `with open ('C:\Users\chhav\OneDrive\Desktop\mnist.pkl','r') as f:` – Gulzar Oct 27 '20 at 08:02
  • Does this answer your question? [(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape](https://stackoverflow.com/questions/37400974/unicode-error-unicodeescape-codec-cant-decode-bytes-in-position-2-3-trunca) – Tomerikoo Oct 27 '20 at 09:57

3 Answers3

0

the file path needs to be a raw string to avoid the backslashes. r'filepath'

with open(r'C:\Users\chhav\OneDrive\Desktop\mnist.pkl','rb') as f:
           mnist_data = pickle.load(f)
nihilok
  • 1,325
  • 8
  • 12
  • or you could alternatively use forward slashes, or escape the backslashes with the same effect - using r string is the easiest way for you tho - fewest changes. – nihilok Oct 27 '20 at 08:33
0

try using:

with open ('C:/Users/chhav/OneDrive/Desktop/mnist.pkl','rb') as f:
    mnist_data = pickle.load(f)

I believe the backslash is interpreted as a protection for special characters

Wazaa
  • 136
  • 3
0

escaping the backslash in file path with one extra backslash could fix this

with open ('C:\\Users\\chhav\\OneDrive\\Desktop\\mnist.pkl','rb') as f:
    mnist_data = pickle.load(f)
Wilson.F
  • 49
  • 3