Veneer Project Computer Science with Python Career Path

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(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):
    
    self.listings.append(new_listing)
    
def remove_listing(self,expire):
    self.listings.remove(expire)
    
def show_listing(self):
    for elem in self.listings:
        print(elem)

class Client:

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


def sell_artwork(self,artwork,price):
    if artwork.owner == self:
        new_listing = Listing(artwork,price,self)
        veneer = veneer.add_listing(new_listing)
def buy_artwork(self,artwork):
    
    if artwork.owner != self:
        art_listing = None
        for listing in veneer.listings:
            if listing.art == artwork:
                art_listing = listing
                break
        if art_listing != None:
            art_listing.art.owner = self
            veneer.remove_listing(art_listing)

veneer = Marketplace()
edytta = Client(“Edytta Halpir”,None,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)

class Listing:

def __init__(self,art,price,seller):
    self.art = art # equals to 
    self.price = price
    self.seller = seller # an instance of Client
    
def __repr__(self):
    return "{}, {}".format(self.art.title,self.price)

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

veneer.show_listing()

moma.buy_artwork(girl_with_mandolin)
veneer.show_listing()

I’ve a doubt how come we use veneer object inside a class,
this is throwing this error
UnboundLocalError: local variable ‘veneer’ referenced before assignment

Without checking your code in detail it sounds like you’re using veneer inside a class somewhere. Ideally you should avoid that kind of hard coding inside classes and functions. If you must use it then consider passing that object as an argument to be used and work with the object that way.

UnboundLocalError suggests that you’re trying to assign to a name whilst simultaneously referencing it from an outer scope which isn’t permitted (it even sounds confusing). Are you making a new variable inside the function or are you altering the one outside? If you have a quick search online you’ll find a lot of details and neat examples about this.

@tgrtim Thanks For your Reply, samething pop with me when i was going throgh the walk through video,
it was being coded by the tutor. As i followed his code,now i don’t know how i can define that object inside a class,can you fix this.

Thanks Again For your Reply.