Hi,
I’m currently trying to complete this exercise:
Check that artwork.owner is the same (==) as self (i.e., make sure the client owns the art they’re trying to sell).
Create a new Listing with the given art, price, and client.
Add the listing to the marketplace using veneer.add_listing().
However when i am using my show_listing method it prints the new listing I have just added using the previous function but then in addition print a Type Error. I’ve attached what gets printed out below including the error.
Girl with a Mandolin (Fanny Tellier) for sale at $6M.
Traceback (most recent call last):
File "script.py", line 92, in <module>
veneer.show_listings()
File "script.py", line 53, in show_listings
print(listing)
TypeError: __str__ returned non-string (type NoneType)
As you can see it prints out the listing correctly but then adds an additional error message. Im a little stuck to why this is.
My full code is pasted here:
#Listings Class
class Listings:
def __init__(self, art, price, seller):
self.art = art
self.price = price
self.seller = seller
def __repr__(self):
print("{n} for sale at {p}.".format(n=self.art.title, p = self.price))
# Client class
class Client:
def __init__(self, name, location, is_museum):
self.name = name
self.location = location
self.is_muesum = is_museum
def sell_artwork(self, artwork, price):
if artwork.owner == self:
new_listing = Listings(artwork, price, self)
veneer.add_listing(new_listing)
else:
print("You can't sell this piece")
def buy_artwork(self, artwork):
if not(artwork.owner == self) and artwork in veneer.listing:
art_listing = veneer.listing.index(artwork)
artwork.owner = self
veneer.remove_listing(art_listing)
# Marketplace class
class Marketplace:
def __init__ (self):
self.listings = []
def add_listing(self, new_listing):
self.listings.append(new_listing)
def remove_listing(self, old_listing):
self.listings.remove(old_listing)
def show_listings(self):
for listing in self.listings:
print(listing)
#ART class
class Art:
def __init__(self, artist, title, medium, year, owner):
self.artist = artist
self.title = title
self.medium = medium
self.year = year
self.owner = owner
def __repr__(self):
return "{n}. \"{t}\". {y}, {m}. {o}, {l}.".format(n = self.artist, t = self.title, y = self.year, m = self.medium, o = self.owner.name, l = self.owner.location)
# Marketplace Instances
veneer = Marketplace()
# Client Instances
edytta = Client("Edytta Halpirt", "Private Collection", False)
moma = Client("The MOMA", "new York", True)
# Art instance
girl_with_mandolin = Art("Picasso, Pablo", "Girl with a Mandolin (Fanny Tellier)", "oil on canvas", 1910, edytta)
#test
edytta.sell_artwork(girl_with_mandolin, "$6M")
veneer.show_listings()