Create an Art Marketplace - Veneer Project

My code will generate an error and I cannot find the mistake, even though watching the Project Walkthrough. I’ve been banging my head against the wall for a couple of hours now. Any help will be greatly appreciated. The error:

Traceback (most recent call last):
File “script.py”, line 110, in
veneer.show_listings()
File “script.py”, line 35, in show_listings
print(listing)
TypeError: str returned non-string (type NoneType)

The code:

# 2.
class Art():
  # 3.
  # 19a.
  def __init__(self, artist, title, medium, year, owner):
    self.artist = artist
    self.title = title
    self.medium = medium
    self.year = year
    # 19b.
    self.owner = owner

  # 4.
  # 20.
  def __repr__(self):
    return '{artist}. "{title}\". {year}, {medium}. {owner_name}, {owner_location}.'.format(artist = self.artist, title = self.title, year = self.year, medium = self.medium, owner_name = self.owner.name, owner_location = self.owner.location)

# 7.
class Marketplace():
  # 8.
  def __init__(self):
    self.listings = []

  # 9.
  def add_listing(self, new_listing):
    self.listings.append(new_listing)
  
  # 10.
  def remove_listing(self, remove_listing):
    self.listings.remove(remove_listing)
  
  # 11.
  def show_listings(self):
    for listing in self.listings:
      print(listing)

# 14.
class Client():
  # 15.
  def __init__(self, name, location, is_museum):
    self.name = name
    self.is_museum = is_museum
    if is_museum:
      self.location = location
    else:
      self.location = 'private Collection'
  
  # 26.
  def sell_artwork(self, artwork, price):
    if self == artwork.owner:
      new_listing = Listing(artwork, price, self)
      veneer.add_listing(new_listing)
      print('listing added')
    else:
      print('The selling client is not the artwork owner')

  # 29.
  def buy_artwork(self, artwork):
    if self != artwork.owner:
      art_listing = None
    # 30.
    for listing in veneer.listings:
      if listing.art == artwork:
       art_listing = listing
       break
    # 31.
    artwork.owner = self
    veneer.remove_listing(art_listing)

# 23.
class Listing:
  # 24.
  def __init__(self, art, price, seller):
    self.art = art
    self.price = price
    self.seller = seller

  # 25.
  def __repr__(self):
    print('{art}, {price}'.format(art = self.art.title, price = self.price))

# 5.
# girl_with_mandolin = Art('Picasso, Pablo', 'Girl with a Mandolin (Fanny Tellier)', 'oil on canvas', '1910')

# 6.
# print(girl_with_mandolin)

# 12.
veneer = Marketplace()

# 13.
veneer.show_listings()

# 16.
edytta = Client('Edytta Halpirt', None, False)

# 17.
moma = Client('The MOMA', 'New York', True)

# 21.
girl_with_mandolin = Art('Picasso, Pablo', 'Girl with a Mandolin (Fanny Tellier)', 'oil on canvas', '1910', edytta)

# 22.
print(girl_with_mandolin)

# 27.
edytta.sell_artwork(girl_with_mandolin, '$6M (USD)')

# 28.
veneer.show_listings()

# 32.
moma.buy_artwork(girl_with_mandolin)

# 33.
print(girl_with_mandolin)

# 34.
veneer.show_listings()

I’ve not checked in detail but I believe you have an issue with the Listing class and an in particular __repr__(). Check up on how __repr__ should be used.

Thank you so much! Greatly appreciated!
As usual it’s so simple. I’m just insufficiently experienced at interpreting the errors.
My definition of the .repr() method generates None instead of a string. Just replace print with return and presto.
It’s a good thing, I can enjoy my own coding mistakes even though they cost me hours.
Thanks again!

1 Like