Reputation:
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.
Upvotes: 0
Views: 41
Reputation: 636
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'):
Upvotes: 2