0
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.

1

1 Answer 1

2

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

I'd say watch some YouTube tutorials, and have a look over the handbook: pillow.readthedocs.io/en/3.0.x/handbook/index.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.