0

I tried to make a simple program that tells me information about an Image. But when i try to change the image folder with os.chdir()

from PIL import Image
import os
os.chdir('C:\Users\Yonatan\PycharmProjects\Python Programs\Color')

i get this error code: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

Please help. ~Yonatan Cohen

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52

1 Answers1

0
r'C:\Users\kallz\Desktop\alice.txt'. 

That way, everything in the string is interpreted as a literal character, and you don't have to escape every backslash.

That means, r'C:\Users\kallz\Desktop\alice.txt' will evaluate to 'C:\Users\kallz\Desktop\alice.txt'' - without causing the backslash to escape characters.

in your Code

from PIL import Image
import os
os.chdir(r'C:\Users\Yonatan\PycharmProjects\Python Programs\Color')
Kallz
  • 3,244
  • 1
  • 20
  • 38