0

I am trying to have each line be stored in a different element of the list. The text file is as follows...

244
Large Cake Pan
7
19.99
576
Assorted Sprinkles
3
12.89
212
Deluxe Icing Set
6
37.97
827
Yellow Cake Mix
3
1.99
194
Cupcake Display Board
2
27.99
285
Bakery Boxes
7
8.59
736
Mixer
5
136.94

I am trying to have 244, 576, etc. be in ID. And "Large Cake Pan","Assorted Sprinkles", etc. in Name. You get the idea, but it's storing everything in ID, and I don't know how to make it store the information in its corresponding element.

Here is my code so far:

import Inventory

def process_inventory(filename, inventory_dict):
    inventory_dict = {}
    inventory_file = open(filename, "r")
    for line in inventory_file:
        line = line.split('\n')
        ID = line[0]
        Name = line[1]
        Quantity = line[2]
        Price = line[3]
        my_inventory = Inventory.Inventory(ID, Name, Quantity, Price)
        inventory_dict[ID] = my_inventory
    inventory_file.close()
    return inventory_dict

def main():
    inventory1={}
    process_inventory("Inventory.txt", inventory1)
quamrana
  • 37,849
  • 12
  • 53
  • 71
  • Do the answers to this [question](https://stackoverflow.com/questions/6335839/python-how-to-read-n-number-of-lines-at-a-time) help at all? – quamrana Dec 03 '22 at 21:05

0 Answers0