' :\\py \\futureproofpython pythoninfo wiki_filesb' :\\py \\oakwinter_com code \xbb porting setuptools to py k_filesb' :\\py \\what\ new in python \ python documentationfor (dirsubsfilesin os walk(root)print(dir encode() ' :\\py ' :\\py \\futureproofpython pythoninfo wiki_filesb' :\\py \\oakwinter_com code \xc \xbb porting setuptools to py k_filesb' :\\py \\what\xe \ \ new in python \xe \ \ python documentationunfortunatelyeither approach means that all the directory names printed during the walk display as cryptic byte strings to maintain the better readability of normal stringsi instead opted for the exception handler approach used in the script' code this avoids the issues entirelyfor (dirsubsfilesin os walk(root)tryprint(direxcept unicodeencodeerrorprint(dir encode()or simply punt if enocde may fail too :\py :\py \futureproofpython pythoninfo wiki_files :\py \oakwinter_com code >porting setuptools to py k_files ' :\\py \\what\xe \ \ new in python \xe \ \ python documentationoddlythoughthe error seems more related to printing than to unicode encodings of filenames--because the filename did not fail until printedit must have been decodable when its string was created initially that' why wrapping up the print in try sufficesotherwisethe error would occur earlier moreoverthis error does not occur if the script' output is redirected to fileeither at the shell level (bigext-tree py :out)or by the print call itself (print(dirfile= )in the latter case the output file must later be read back in binary modeas text mode triggers the same error when printing the file' content to the shell window (but againnot until printedin factthe exact same code that fails when run in system shell command prompt on windows works without error when run in the idle gui on the same platform--the tkinter gui used by idle handles display of characters that printing to standard output connected to shell terminal window does notimport os run in idle ( tkinter gui)not system shell root ' :\py for (dirsubsfilesin os walk(root)print(dirc:\py :\py \futureproofpython pythoninfo wiki_files :\py \oakwinter_com code >porting setuptools to py k_files :\py \what' new in python -python documentation_files in other wordsthe exception occurs only when printing to shell windowand long after the file name string is created this reflects an artifact of extra translations quick game of "find the biggest python file