|
| 1 | +""" |
| 2 | +From Brian Dorsey's Internet Programming in Python, Winter 2011 |
| 3 | +""" |
| 4 | + |
| 5 | +class BookDB(): |
| 6 | + def titles(self): |
| 7 | + titles = [dict(id=id, title=database[id]['title']) for id in database.keys()] |
| 8 | + return titles |
| 9 | + |
| 10 | + def title_info(self, id): |
| 11 | + return database[id] |
| 12 | + |
| 13 | + |
| 14 | +# let's pretend we're getting this information from a database somewhere |
| 15 | +database = { |
| 16 | + 'id1' : {'title' : 'CherryPy Essentials: Rapid Python Web Application Development', |
| 17 | + 'isbn' : '978-1904811848', |
| 18 | + 'publisher' : 'Packt Publishing (March 31, 2007)', |
| 19 | + 'author' : 'Sylvain Hellegouarch', |
| 20 | + }, |
| 21 | + 'id2' : {'title' : 'Python for Software Design: How to Think Like a Computer Scientist', |
| 22 | + 'isbn' : '978-0521725965', |
| 23 | + 'publisher' : 'Cambridge University Press; 1 edition (March 16, 2009)', |
| 24 | + 'author' : 'Allen B. Downey', |
| 25 | + }, |
| 26 | + 'id3' : {'title' : 'Foundations of Python Network Programming', |
| 27 | + 'isbn' : '978-1430230038', |
| 28 | + 'publisher' : 'Apress; 2 edition (December 21, 2010)', |
| 29 | + 'author' : 'John Goerzen', |
| 30 | + }, |
| 31 | + 'id4' : {'title' : 'Python Cookbook, Second Edition', |
| 32 | + 'isbn' : '978-0-596-00797-3', |
| 33 | + 'publisher' : 'O''Reilly Media', |
| 34 | + 'author' : 'Alex Martelli, Anna Ravenscroft, David Ascher', |
| 35 | + }, |
| 36 | + 'id5' : {'title' : 'The Pragmatic Programmer: From Journeyman to Master', |
| 37 | + 'isbn' : '978-0201616224', |
| 38 | + 'publisher' : 'Addison-Wesley Professional (October 30, 1999)', |
| 39 | + 'author' : 'Andrew Hunt, David Thomas', |
| 40 | + }, |
| 41 | +} |
| 42 | + |
0 commit comments