I'd like to find a function that accesses a directory using the os.listdir() function (or any other method) and returns all the file names in that directory but converts non-ASCII characters into their unicode format. For example, if I had the file Hello WorlЪ.py
, I'd like for the function to return Hello Worl\u042a.py
or something equivalent. Any help is appreciated.
If you pass os.listdir
a unicode path, then os.listdir
returns unicode:
os.listdir(u'.')
From the docs:
Changed in version 2.3: On Windows NT/2k/XP and Unix, if path is a Unicode object, the result will be a list of Unicode objects. Undecodable filenames will still be returned as string objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With