# L-21 MCS 260 Mon 15 Oct 2007 : books # # This module defines the formats in which we # store the information of a book on file, e.g.: # # '1:2:Making Use of Python:' # The format of a book is a string of 3 fields: # (1) availability, (2) key, (3) title. def pack(key,status,title): "returns the string with book information\n\ where key is the book identification number,\n\ status is True or False for availability,\n\ title is the title of the book" if status: s = '1:' else: s = '0:' s += '%d:' % key s += title + ':\n' return s def get_status(s): "given a string with book information,\n\ returns True or False for the availability" L = s.split(':') return int(L[0]) == 1 def get_key(s): "given a string with book information,\n\ returns the identification number of the book" L = s.split(':') return int(L[1]) def get_title(s): "given a string with book information,\n\ returns the title of the book" L = s.split(':') return L[2]