Why is the owner argument in girl_with_mandolin getting passed as str instead of object

Here is my code

class Art:
  def __init__(self, artist, title, year,medium, owner):
    self.artist = artist
    self.title = title
    self.medium = medium
    self.year = year
    self.owner = owner

  def __repr__(self):
    return "{}. \"{}\". {}, {}. {}, {}".format(self.artist, self.title, self.year, self.medium, self.owner.name, self.owner.location)

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

  def add_listing(self, new_listing):

  def remove_listing(self, listing):

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

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

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

  def buy_artwork(self, artwork):
    if artwork.owner != self:
      art_listing = None
      for listing in veneer.listings:
        if listing.art == artwork:
          art_listing = listing
      if art_listing != None:
        art_listing.art.owner = self.name

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

  def __repr__(self):
    return "{}, {}.".format(self.art.title, self.price)

veneer = Marketplace()

edytta = Client("Edytta Halpirt", None, False)

moma = Client("The MOMA", "New York", True)

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

edytta.sell_artwork(girl_with_mandolin, 6000000)



Have you checked exactly what it is that you are passing? You could print it out and perhaps checking the type() or similar would be helpful.

its getting passed as object but after the name is being changed it is getting passed as a string.

When you change .owner what do you assign to it?

art_listing.art.owner = self.name

What is self.name and what type does it have?

it is the name of the client and is string type

That it is. Based on your title what did you actually want?

I want it to be passed an an object so that I can call self.owner.loaction on it. Since str doesn’t support that

The .name is just an attribute of a Client instance so if we pass that then we’ll only get whatever that attribute references. What’s the standard way of getting any created instances to reference themselves when defining your class?

I didn’t quite get what you asked

When you create a class there’s very particular way of getting any instances (objects) created from that class to refer to themselves. What is it?

are you talking about self argument?

That’s the one. So if self can be used to make an instance object refer to itself what do we want to be assigning to .owner?

yeah so that the location can be extracted from the owner as it is being passed in the client class

I am gussing self.name ?

Your initial issue was that a string was passed instead of an object. Looking into what was assigned we noted self.name is a string. So passing self.name is what caused your initial issue. So what should you be assigning to .owner instead?

If you’re unsure check what you initially assigned as the .owner of a particular piece of Art.

I assigned self.owner initially and the owner was an Object

This worked fine until I changed the owners name in .buy_artwork()

What’s the difference between those two assignments? Check very carefully what you used the first time around and what you’re using in .buy_artwork.