I have the following code which works fine : this is class parent order1
class order1:
def __init__(self, type: str, quantity: int) -> None:
self._type = type
self._quantity = quantity
self.members = []
def __str__(self) -> str:
return f'{self._type},{self._quantity}'
def add_order(self, type, quantity) -> str:
order = order1(type, quantity)
if type not in self.members:
self.members.append(order)
else:
print('type already exist')
# return order
@property
def type(self) -> str:
return self._type
@type.setter
def type(self, type) -> None:
self._type = type
@property
def quantite(self) -> int:
return self._quantite
@quantite.setter
def quantite(self, quantite) -> None:
self._quantite = quantite
#item_list.append(item) if item not in item_list else None
if __name__ == '__main__':
test = order1("nokia22", 1233)
test2 = test.add_order("nokia22", 123)
print(test)
print(test2)
i have two attributes type of a phone and quantity of same type now i need to create another class to display the inherited attributes from class parent that's what i've done so far
from order import order1
from phone import phone1
class card( order1):
def __init__(self):
self.members1 = []
def __str__(self):
return '||'.join(str(x) for x in self.members)
if __name__ == '__main__':
test = card()
print(test.self.members)
this is the error that i got : NameError: name 'test' is not defined and the expected solution was for the list of orders to be displayed self.members is a list from the class parent