Os.walk () strips polish symbol

So I'm trying to fix some id3tags mp3 files. All this works, except for files with any accent, because os.walk seems to strip them.

For example, I have a file 01.Co Sล‚ychaฤ‡.mp3 , which in this code:

 for root, dirs, files in os.walk(folder): print files 

It is shown as ['01.Co Slychac.mp3'] , later as a result an error โ€œNo such file or directoryโ€ appears.

How can this be fixed?

+6
source share
1 answer

Have you defined folder as a Unicode string? This affects how os.walk() matches its subdirectories or, better, the type of return line.

 >>> for a,b,c in os.walk("."): ... print b ... break ... ['DLLs', 'Doc', 'include', 'Lib', 'libs', 'tcl', 'Tools'] >>> for a,b,c in os.walk(u"."): ... print b ... break ... [u'DLLs', u'Doc', u'include', u'Lib', u'libs', u'tcl', u'Tools'] 
+7
source

Source: https://habr.com/ru/post/898009/


All Articles