I have a program that reads lines from a textfile, each line contains a word, such as price or product name. The program reads through all lines and saves each word in a list. Each product in the file contains of three lines, which are: product name, price and weight. So in the list will look like the following: ['Mjölk', '15 kr', '1 liter', 'Köttfärs', '80 kr', '1 kg', 'Morötter', '20 kr', '1 kg']
Now to the problem, I have the class:
class Produkt:
def __init__(self, produkt, pris, vikt):
self.produkt = produkt
self.pris = pris
self.vikt = vikt
I want to make Produkt objects from the items from the list, but I don't know how to loop through the items in the list and then save them as objects. I was thinking I'd make a list for the objects, and then like: for item in listofprodukts: objectlits.append(Produkt(item, item,item))
but this does obviously not work, anyone have an idea how to do this?