Hi everyone, in my code below, can anyone please quickly explain how ‘artwork.owner’ in the method .sell_artwork of my Client class is able to access the owner parameter of my Art class?

same with the {} in the ‘repr’ of my Listing class. how is title retrieved from the Art class?

i cant make the connection. Please help me understand

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 f'''
artist's name: {self.artist}
network name : "{self.title}"
medium : {self.medium}
year created : {self.year}
owner: {}.
location: {self.owner.location}.

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

  def add_listing(self, new_listing):

  def remove_listing(self, expired_listing):

  def show_listings(self):
    for listing in self.listings:

class Client:
  def __init__(self, name, location, is_museum): = name
    self.is_museum = is_museum
    if is_museum:
      self.location = location
      self.location = "Private Collection"      

  def __repr__(self):
    return f'''
  It is a museum: {self.is_museum} 
  def sell_artwork(self, artwork, price):
    if artwork.owner == self:
      new_listing = Listing(artwork, price, self)

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

  def __repr__(self):
    return f'''

veneer = Marketplace()


edytta = Client("Edytta Halprint", "collector", False)
moma =Client("The MOMA", "New York", True)

girl_with_mandolin = Art("Picasso, Pablo", "Girl with a Mandolin (Fanny Tellier)", "oil on canvas", 1910, edytta)

#print(moma, edytta)

edytta.sell_artwork(girl_with_mandolin, "$6M (USD)")


result prints:

    Girl with a Mandolin (Fanny Tellier)
    $6M (USD)

exercise link:

1 Like

Hi @seppp,

Whenever you create an instance of Art, its __init__ method creates an owner variable that belongs to that instance, as follows:

    self.owner = owner

Thereafter, you can use dot notation to access the owner instance variable wherever that instance of Art is accessible. Within the sell_artwork method of Client, if an instance of Art is represented by the variable artwork, that instance is guaranteed to have an owner instance variable, and that variable is accessible as artwork.owner.

Similarly, in the Listing class or anywhere else, every instance of Art has all the instance variables that were created by the __init__ method of Art, and those variables are accessible via dot notation.


oh ok i think i got it, and for the string:

def sell_artwork(self, artwork, price):
    if artwork.owner == self:
      new_listing = Listing(artwork, price, self)

we created an instance of Listing inside the Client class only accessible to client, cuz there is no other instance for Listing.

thank you very much

Yes, the variable, new_listing, that is created here is local to the method, and is only recognized in the sell_artwork method:

      new_listing = Listing(artwork, price, self)

However, here we pass that instance to a method called from veneer, making that instance of Listing available to the veneer object within its listings instance variable:


yes thats right got it finally! thanks for the explanation and help

1 Like