Python Forum
create a list of object with a list of character
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
create a list of object with a list of character
Hello i am french student and i work on a first python 3.7 project

My problem is the following
i have create and object "ingredient" with 4 parameter

Now i have to create a list of object "ingredient" with information contain in a file .TXT
i have done the following programm but the list of object isn't generate

here are some sample of my code :

1- My object "ingredient"
 def __init__(self, nom: str, quantite: int, unite: str, vegetarien: str) -> None:
        # Crée un nouvelle ingrédient. pour le nom, quantite, unite, vegetarien

        self._nom = nom
        self._quantite = quantite
        self._unite = unite
        self._vegetarien = vegetarien
2- "open file txt and create a first list from the file"
 liste_ingredients = []
    with open("stock.txt", "r") as f:
        for line in f.readlines():
            # print(line)
    del liste_ingredients[0]

3- The part that doesn't work the goal was to generate a list of object in placard list"
placard = []

    for i in liste_ingredients:
        i[0] = ingredient(i[0], i[1], i[2], i[3])

Thanks a lot for your answer and have a good day ;)

Finally we find our problem

i only had to say when it is int type
i[0] = ingredient(i[0], int(i[1]), i[2], i[3])

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a linked list and call it? loves 12 250 Nov-22-2020, 03:50 PM
Last Post: loves
  Creating list of lists from generator object t4keheart 1 121 Nov-13-2020, 04:59 AM
Last Post: perfringo
  Count number of occurrences of list items in list of tuples t4keheart 1 108 Nov-03-2020, 05:37 AM
Last Post: deanhystad
Question Save list with nested list into CSV SpongeB0B 1 222 Oct-12-2020, 07:26 AM
Last Post: bowlofred
  Appending to list of list in For loop nico_mnbl 2 196 Sep-25-2020, 04:09 PM
Last Post: nico_mnbl
  How to make a list of values from a dictionary list? faryad13 2 241 Sep-03-2020, 03:45 PM
Last Post: faryad13
  TypeError: 'list' object is not callable Python_Mey 1 340 Aug-25-2020, 03:56 PM
Last Post: Yoriz
  How to create and define in one line a 2D list of class objects in Python T2ioTD 1 235 Aug-14-2020, 12:37 PM
Last Post: Yoriz
  How to define a function to create a resorted list? sparkt 6 413 Aug-08-2020, 04:10 PM
Last Post: sparkt
  Append list into list within a for loop rama27 2 370 Jul-21-2020, 04:49 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020