from PIL import Image
import os
for f in os.listdir('C:\Users\diodi\Pictures'):
if f.endswith('.jpg'):
print(f)
i get the error
for f in os.listdir('C:\Users\diodi\Pictures'): ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
if someone can edit the error message please do.
i want to print the names of the pictures(jpg) i have in ('C:\Users\diodi\Pictures')
i am using python 3.7,i know i didn't use the pillow library yet.
asked Sep 3, 2018 at 17:47
user10296334
-
1Possible duplicate of Why do I get a SyntaxError for a Unicode escape in my file path?smoggers– smoggers2018年09月03日 17:49:13 +00:00Commented Sep 3, 2018 at 17:49
1 Answer 1
The backslashes are being parsed as escape characters, use r to denote raw string
os.listdir(r"C:\Users\diodi\Pictures"):
Or escape them with more backslashes
os.listdir('C:\\Users\\diodi\\Pictures'):
Sign up to request clarification or add additional context in comments.
1 Comment
Sam
I'd say watch some YouTube tutorials, and have a look over the handbook: pillow.readthedocs.io/en/3.0.x/handbook/index.html
lang-py