Marquette University, view of Wisconsin Avenue  

Module 16

Encodings

Over the short history of electronic computing, a large number of ways to encode data have been developed. For instance, there is a difference in how line breaks are encoding in the Windows and the Unix worlds. Python has a large number of encodings, which it can understand, i.e. which it can change to its own internal encodings. By default, Python now assumes utf-8, a version of unicode that is compact and therefore popular. Python throws encoding errors if it sees a sequence of bits that it cannot make sense of. The one exception is the "latin-1" encoding, which represents the lower half of the traditional ASCII code.

OS Module

To interact with the file system, Python programmers should import the os module (for Operating System). With the listdir method, the programmer obtains the list of files in the directory. This list can then be used to process all files (with a certain extension or conforming to a certain naming pattern) in a directory. This is a useful automation tools. Python excels at processing files, as we already have seen.