I am currently working on an inventory system that I have mocked up so far.
This is the following code:
import csv
class start_store:
def __init__(self):
self.name = self.ask()
self.options = self.ask_options()
def ask(self):
while 1:
name = input("What is your name?\n")
if name == "":
print("Ha! You have to enter a name!")
else:
print("Welcome to the Shepherdstown Bake Shop " + name)
return name
def ask_options(self):
while 1:
option = input('''What would you like to do? \n1. Add a Item: \n2. Delete a Item:\n3. Edit an Item: \n4. View Inventory \n5. End Program\n''')
if option == "4":
print("Here is the following inventory we have " + self.name)
items = CsvReader()
items.make_dict_items()
items.show_available()
break
else:
print("You have to enter a valid option " + self.name)
and the second class:
class CsvReader:
def __init__(self):
self.result = []
def make_dict_items(self):
with open("Items2.csv") as fp:
reader = csv.reader(fp)
labels = next(reader, None)
result = []
for row in reader:
row[0] = int(row[0])
row[1] = float(row[1])
row[2] = int(row[2])
pairs = zip(labels, row)
self.result.append(dict(pairs))
def show_available(self):
for item in self.result:
print(item)
obj = start_store() # create the instance
while 1:
obj.ask_options() # use the instance
From what I understand, I am able to run my code in IDLE based upon the last three lines in my second class, which initialize, and run. The program runs from : asking the user their name -> asking the user what they would like to do -> performing said task-> looping back to ask what to do.
I am confused on how I would implement a main method that runs my current program in that order? I understand how to make a main method, it being if __name__ == '__main__': , but what would I put under it? Would I have it run ask() like in the bottom of my lines? How do I add a main method that runs my program in this order in the sense that it is able to run now in IDLE without a main method?
I apologize if I am overlooking something, I am fairly new to Python and OOP.