Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAnthony Costanza
2,123 PointsNot sure how to even find the answer to this...
Not sure how to even find the answer to this...
class Book:
def __init__(self, author, title):
self.author = author
self.title = title
def __iter__(Bookcase)
def __str__(self):
return f'{self.author}, {self.title}'
def __eq__(self, other):
return self.author == other.author and self.title == other.title
from book import Book
class BookCase:
def __init__(self):
self.books = []
def add_books(self, book):
self.books.append(book)
2 Answers
Mel Rumsey
Treehouse ModeratorHeya Anthony Costanza,
Since we are wanting to iterate through the list that is located in the BookCase class, we want to add the __iter__(self):
method inside of that class in bookcase.py rather than the Book class in the book.py file.
Then we want it to yield from self.books
Hopefully, this helps. Let us know if you are still stuck! Keep up the good work :D
ali ghasemnejad
3,410 PointsHi My friends, Hopefully, the code below worked for me. Keep up the good work :D
from book import Book class BookCase: def init(self): self.books = []
def add_books(self, book):
self.books.append(book)
def __iter__(self):
yield from self.books
Leslio McKeown
Python Development Techdegree Student 9,441 PointsLeslio McKeown
Python Development Techdegree Student 9,441 Pointsit keeps saying 'BookCase' object has no attribute 'books'