A
A
ace6062021-11-14 14:41:31
Python
ace606, 2021-11-14 14:41:31

TypeError: descriptor 'append' for 'list' objects doesn't apply to a 'RetailItem' object?

Just started taking classes. I'm trying to add an instance of one class to the list of an instance of another class. The output is:
Traceback (most recent call last):
File "C:\Users\Ace\Desktop\Python\Classes\RetailItem Class\#test ver2.py", line 23, in
main()
File "C:\Users \Ace\Desktop\Python\Classes\RetailItem Class\#test ver2.py", line 17, in main
operation.purchase_item(obj)
File "C:\Users\Ace\Desktop\Python\Classes\RetailItem Class\CashRegister_ver2. py", line 9, in purchase_item
list.append(obj)
TypeError: descriptor 'append' for 'list' objects doesn't apply to a 'RetailItem' object

What am I doing wrong and how can I fix it?

Source:

#Класс RetailItem(розничная товарная единица)
class RetailItem:
    def __init__(self, description, number, price):
        self.__description = description
        self.__number = number
        self.__price = price
    def set_number(self, number):
        self.__number = number
    def get_number(self, number):
        return self.__number
    def get_price(self):
        return self.__price
    def __str__(self):
        return "Описание: " + self.__description + \
               "\nКол-во на складе: " + self.__number + \
               "\nЦена: " + self.__price


#CashResister(кассовый аппарат)ver2
import RetailItem as rt
class CashRegister:
    def __init__(self, total): #инициализация
        self.__total = total
        self.__lst = []
    def purchase_item(self, obj): #приобрести товар
        self.__lst.append(obj)            
    def __str__(self):
        return str(self.__list_price)


#main()
import RetailItem as ri
import CashRegister_ver2 as cr
def main():
    print("Добро пожаловать в кассу")
    print("Готовы совершить покупки Д/Н ?")
    stop = input(':')
    total = 0
    lst = []
    operation = cr.CashRegister(total)
    while stop.upper() == "Д":
        name = input("Введите товар:")
        count = input("Введите кол-во для покупки:")
        price = input("Введите цену за еденицу:")
        obj = ri.RetailItem(name, count, price)
        operation.purchase_item(obj)
        print("Желаете продолжить Д/Н ?")
        stop = input(':')                
    print(operation)
main()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-11-14
@ace606

def purchase_item(self, self.__lst, obj): #purchase an item
1. Where did you get this syntax from?
2. You have a link to self, you can use it to refer to any attribute/method of self.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question