error entirely this demonstrates subtle but pragmatically important issuepython ' unicode orientation extends to filenameseven if they are just printed as we learned in because filenames may contain arbitrary textos listdir returns filenames in two different ways--we get back decoded unicode strings when we pass in normal str argumentand still-encoded byte strings when we send bytesimport os os listdir(')[: ['bigext-tree py''bigpy-dir py''bigpy-path py''bigpy-tree py'os listdir( ')[: [ 'bigext-tree py' 'bigpy-dir py' 'bigpy-path py' 'bigpy-tree py'both os walk (used in the example - scriptand glob glob inherit this behavior for the directory and file names they returnbecause they work by calling os listdir internally at each directory level for all these callspassing in byte string argument suppresses unicode decoding of file and directory names passing normal string assumes that filenames are decodable per the file system' unicode scheme the reason this potentially mattered to this section' example is that running the tree search version over an entire hard drive eventually reached an undecodable filename (an old saved web page with an odd name)which generated an exception when the print function tried to display it here' simplified recreation of the errorrun in shell window (command prompton windowsroot ' :\py for (dirsubsfilesin os walk(root)print(dirc:\py :\py \futureproofpython pythoninfo wiki_files :\py \oakwinter_com code >porting setuptools to py k_files traceback (most recent call last)file ""line in file " :\python \lib\encodings\cp py"line in encode return codecs charmap_encode(input,self errors,encoding_map)[ unicodeencodeerror'charmapcodec can' encode character '\ in position character maps to one way out of this dilemma is to use bytes strings for the directory root name--this suppresses filename decoding in the os listdir calls run by os walkand effectively limits the scope of later printing to raw bytes since printing does not have to deal with encodingsit works without error manually encoding to bytes prior to printing works toobut the results are slightly differentroot encode( ' :\\py for (dirsubsfilesin os walk(root encode())print(dir complete system programs