names that can be successfully decoded as unicode if dirname is string if dirname is byte stringthen all filenames are returned as byte strings new / system python implements an entirely new / systemthe details of which are described in the io module section of "operating system services "the new / system also reflects the strong distinction between text and binary data present with strings if you are performing any kind of / with textpython forces you to open files in "text modeand to supply an optional encoding if you want anything other than the default (usually utf- if you are performing / with binary datayou must open files in "binary modeand use byte strings common source of errors is passing output data to file or / stream opened in the wrong mode for examplef open("foo txt","wb" write("hello world\ "traceback (most recent call last)file ""line in file "/tmp/lib/python /io py"line in write raise typeerror("can' write str to binary stream"typeerrorcan' write str to binary stream socketspipesand other kinds of / channels should always be assumed to be in binary mode one potential problem with network code in particular is that many network protocols involve text-based request/response processing ( httpsmtpftpetc given that sockets are binarythis mix of binary / and text processing can lead to some of the problems related to mixing text and bytes that were described in the previous section you'll need to be careful print(and exec(functions the print and exec statements from python are now functions use of the print(function compared to its python counterpart is as followsprint( , ,zprint( , , ,end='print( ,file=fsame as print xyz same as print xyzsame as print >>fa the fact that print(is function that means you can replace it with an alternative definition if you want exec(is also now functionbut its behavior in python is subtly different than in python for exampleconsider this codedef foo()exec(" "print(ain python calling foo(will print the number ' in python you get nameerror exception with the variable being undefined what has happened here is that exec()as functiononly operates on the dictionaries returned by the globals(and locals(functions howeverthe dictionary returned by locals(is actually copy of the local variables the assignment made in the exec(function is lib fl ff