I have an object with a dictionary that I want to access via __getitem__
as well as iterate over (values only, keys don\'t matter) but am not sure how to do it.
>>> class Library(object):
... def __init__(self):
... self.books = { 'title' : object, 'title2' : object, 'title3' : object, }
... def __getitem__(self, i):
... return self.books[i]
... def __iter__(self):
... return self.books.itervalues()
...
>>> library = Library()
>>> library['title']
>>> for book in library:
... print book
...