# L-16 MCS 260 Wed 17 Feb 2010 : 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 where key is the book identification number, status is True or False for availability, 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, 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, returns the identification number of the book """ L = s.split(':') return int(L[1]) def get_title(s): """ given a string with book information, returns the title of the book """ L = s.split(':') return L[2]