Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Book(object):
- """Book class to represent a book in the library."""
- known_fields = ['title', 'authors', 'pages' ... ]
- def __init__(self, **kwargs):
- # internal dict to store book information
- self._info = {}
- for k, v in kwargs.iteritems():
- # check for typos
- Book.check_field_name(k)
- self._info[k] = v
- # either the title or ISBN needs to be provided to identify the book
- if not self.title and not self.ISBN:
- raise InputError('Title or ISBN needed to identify the book')
- self.owned = True if self.file_path != None else False
- self.tags = set()
- def __getattr__(self, name):
- return self._info.get(name, None)
- @staticmethod
- def check_field_name(field_name):
- if not field_name in Book.known_fields:
- warnings.warn('Unknown field: {0}'.format(field_name), UserWarning)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement