(continued from previous pageprint('{ --{ }format(filenamenewname)img_ jpg --ashley_ jpg img_ jpg --ashley_ jpg img_ jpg --ashley_ jpg another application for templating is separating program logic from the details of multiple output formats this makes it possible to substitute custom templates for xml filesplain text reportsand html web reports working with binary data record layouts the struct module provides pack(and unpack(functions for working with variable length binary record formats the following example shows how to loop through header information in zip file without using the zipfile module pack codes "hand "irepresent two and four byte unsigned numbers respectively the "<indicates that they are standard size and in little-endian byte orderimport struct with open('myfile zip''rb'as fdata read(start for in range( )show the first file headers start + fields struct unpack('<iiihh'data[start:start+ ]crc comp_sizeuncomp_sizefilenamesizeextra_size fields start + filename data[start:start+filenamesizestart +filenamesize extra data[start:start+extra_sizeprint(filenamehex(crc )comp_sizeuncomp_sizestart +extra_size comp_size skip to the next header multi-threading threading is technique for decoupling tasks which are not sequentially dependent threads can be used to improve the responsiveness of applications that accept user input while other tasks run in the background related use case is running / in parallel with computations in another thread the following code shows how the high level threading module can run tasks in background while the main program continues to runimport threadingzipfile class asynczip(threading thread)def __init__(selfinfileoutfile)threading thread __init__(selfself infile infile self outfile outfile (continues on next page working with binary data record layouts