Veneer

my code :slight_smile:
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 “{}. {}. {}, {}, {}, {}.” .format(artist, title, medium , year ,owner.name , owner.location )

class Marketplace:

def init(self):
self.listings =

def add_listing(self, new_listing):
self.listings.append(new_listing)

def remove_listing(self, expire_listing):
self.listings.remove(expire_listing)

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

class Client:
def init(self, name, location, is_museum):
self.name = name
self.is_museum = is_museum
if self.is_museum == True:
self.location = location
else:
self.location = “Private Colections”
def sell_artwork(self, artwork, price):
if artwork.owner == self:
new_listing = Listing(artwork, price, self)
venner.add_listing(new_listing)

class Listing:
def init(self, art, price, seller):
self.art = art
self.price = price
self.seller = seller
def repr(self):
return “%s, %s.” %(self.art, self.price)

veneer = Marketplace()

veneer.show_listings()

edytta = Client(“Edytta Halpirt”, None, False)

moma = Client(“MOMA”, “New York”, True)

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

print(girl_with_mandolin)

edytta.sell_artwork(girl_with_mandolin, “6M(USD)”)

code return:

(‘Picasso, Pablo’, ‘Girl with a Mandolin (Fanny Tellier)’, 1910, ‘oil on canvas’, <main.Client object at 0x7f55610d5cc0>)
Traceback (most recent call last):
File “script.py”, line 62, in
edytta.sell_artwork(girl_with_mandolin, “6M(USD)”)
File “script.py”, line 36, in sell_artwork
if artwork.owner == self:
AttributeError: ‘tuple’ object has no attribute 'owner’¨

what problem…main and traceback …help pls

Hi @tony0z,

Your code is not formatted for posting, therefore, it does not exhibit indentation and underscores properly, which makes it difficult to understand. For advice on formatting code for posting, see How to ask good questions (and get good answers).

You defined girl_with_mandolin as a tuple here:

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

Quite likely, you intended to define it as an instance of Art.

1 Like

problem fix…

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 str("The artist: {}, Title of the piece: {}, Medium: {}, Year of creation: {}, Owner: {}".format(self.artist, self.title, self.medium, str(self.year), self.owner))

class Marketplace:
  
  def __init__(self):
    self.listings = []
    
  def add_listing(self, new_listing):
    self.listings.append(new_listing)
    
  def remove_listing(self, expire_listing):
    self.listings.remove(expire_listing)
    
  def show_listings(self):
    for listing in self.listings:
      print(listing)
 
class Client:
  def __init__(self, name, location, is_museum):
    self.name = name
    self.is_museum = is_museum
    if self.is_museum == self:
      self.location = location
    else: self.location = "Private Colections"
  
  def sell_artwork(self, artwork, price):
    if artwork.owner == self:
      new_listing = Listing(artwork, price, self)
      veneer.add_listing(new_listing)

class Listing:
  def __init__(self, art, price, seller):
    self.art = art
    self.price = price
    self.seller = seller
  def __repr__(self):
    return "%s, %s." %(self.art, self.price)

veneer = Marketplace()

veneer.show_listings()

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

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

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


print(girl_with_mandolin)

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

now …

The artist: Picasso, Pablo, Title of the piece: Girl with a Mandolin (Fanny Tellier), Medium: oil on canvas, Year of creation: 1910, Owner: **<__main__.Client object at 0x7f9f476ffc88>**

i dont now why thx for help

<main.Client object at 0x7f9f476ffc88>

Blockquote

1 Like

Since you did not define a __repr__ method for the Client class, you are outputting a default representation of an instance of that class. This specifies the type of the instance and its memory address. If you wish to see a more satisfying output, you could define a __repr__ method for the class.

Edited on October 4, 2019 to add the following:

See:

Note that __repr__ is intended for defining a formal or official string representation of an object, while __str__ is for defining an informal or nicely printable string representation of an object.

1 Like

thx you wery help me…

1 Like

You’re welcome.

Following is a quote from the __repr__ reference cited above, regarding the return value:

If at all possible, this should look like a valid Python expression that could be used to recreate an object with the same value (given an appropriate environment).

Based on that recommendation, the following would be a good __repr__ method for Client:

  def __repr__(self):
    return 'Client("{:s}", "{:s}", {:s})'.format(
      self.name,
      self.location,
      str(self.is_museum)
      )

Your __init__ method for Client needs to be refined a bit. You have:

    if self.is_museum == self:

Instead, just check whether the value of self.is_museum is True or False, as follows:

   if self.is_museum:

You could make an additional modification to the __init__ method, so that the value of the location parameter is saved in an instance variable, even when the Client is not a museum, but that is entirely up to you.

With the modifications made, you can do this:

print(moma)

Output:

Client("MOMA", "New York", True)

Consistent with the recommendation in the documentation for __repr__, that output looks like a valid Python expression that could be used to recreate a Client instance with the same value.

This post was modified on October 5, 2019 to use double quotes in the return value of the __repr__ method. This was done so that if one of the instance variables contained a single quote, for example if it contained a possessive or a contraction, the return value would still look like a valid expression.