file and directory handling his describes python modules for high-level file and directory handling topics include modules for processing various kinds of basic file encodings such as gzip and bzip filesmodules for extracting file archives such as zip and tar filesand modules for manipulating the file system itself ( directory listingsmovingrenamingcopyingand so onlow-level operating system calls related to files are covered in "operating system services modules for parsing the contents of files such as xml and html are mostly covered in "internet data handling and encoding bz the bz module is used to read and write data compressed according to the bzip compression algorithm bz file(filename [mode [buffering [compresslevel]]]opens bz filefilenameand returns file-like object mode is 'rfor reading or 'wfor writing universal newline support is also available by specifying mode of 'rubuffering specifies the buffer size in bytes with default value of (no bufferingcompresslevel is number between and value of (the defaultprovides the highest level of compression but consumes the most processing time the returned object supports all the common file operationsincluding close()read()readline()readlines()seek()tell()write()and writelines(bz compressor([compresslevel]creates compressor object that can be used to sequentially compress sequence of data blocks compresslevel specifies the compression level as number between and (the defaultan instancecof bz compressor has the following two methodsc compress(datafeeds new string data to the compressor objectc returns string of compressed data if possible because compression involves chunks of datathe returned string may not include all the data and may include compressed data from previous calls to compress(the flush(method should be used to return any remaining data stored in the compressor after all input data has been supplied lib fl ff