So I have a class which contains an empty list, static and instance methods. When I add new instances which contain strings to this class, they get appended to this empty list and everything is working correctly. I'm trying to write a function that will get this list and write it in a txt file but instead of the actual content, I'm getting something like this when I try the map() function:
"0x000001E6B9C718D0><Products.Product"
And if I type a simple .join and convert the list to a string, it's showing me this error:
"The Python "TypeError: can only join an iterable"
which tells me the list is not being properly converted to a string.
I've looked online extensively for the past 2 hours but so far nothing. None of the solutions have fixed my problem. Probably because this list is inside a class and instances are getting appended to it but I don't know.
EDIT: Forgot the code here it is:
class Product:
#This class is for adding products.
products = []
def __init__(self, name, serial_number, price):
self.name = name
self.serial_number = serial_number
self.price = price
#Instance method to show the information about an instance.
def show(self):
print("Product's Name:", self.name, "|", "Serial Number:", self.serial_number, "|", "Price:", self.price)
#Class method to add a product to the product's list.
@staticmethod
def add_product(product):
Product.products.append(product)
#Class method to show the info of all products
@staticmethod
def show_products():
for product in Product.products:
product.show()
#Class method to write th items in a txt file:
@staticmethod
def write_list():
file = open("Products.txt", "a")
file.write(''.join(str(Product.products)))