-1

TypeError: Menu() missing 1 required positional argument: 'self'

I have put self.Menu() in init class and still has error, i have tried to also put self.Menu = Menu() and same error issue. i need to use self in the Menu to call the other classes eg. self.addProductsToDB()

class SupermarketDAO:
def __init__(self):
    self.count = None
    self.option = None
    self.barcode = None
    self.cursor = None  # code to get cursor from db
    self.dbCreated = False
    _continue = True
    self.Menu()
    self.startUp()

# menu to ask user what option they would like to choose
def Menu(self):
    print("[1] Add products to Database")
    print("[2] List all products in Database, based on product bar-code")
    print("[3] List all transactions(Ascending order of date of transaction")
    print("[4] Display Barchart of Products sold by quantity")
    print("[5] Display an Excel report of all transactions")
    print("[6] EXIT")
    option = int(input("Enter your option:"))
    while option != 0:
        if option == 1:
            print("go to Add products to Database")
            self.addProductToDB(products)
            break
        elif option == 2:
            print("go to List all products in Database")
            self.listAllProducts()
            break
        elif option == 3:
            print("go to  List all transactions")
            self.listAllTransactions()
            break
        elif option == 4:
            print("go to Display Barchart of Products sold by quantity")
            self.displayBarchartOfProductsSold()
            break
        elif option == 5:
            print("go to Display an Excel report of all transactions")
            self.addProductToDB(products)
            break
        elif option == 6:
            print("EXIT")
            sys.exit()

        else:
            print("invalid option!")  # if no option is chosen print invalid prompt user again to type.
            break
Menu()
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Paige
  • 1
  • 4
  • Is `Menu()` supposed to be a standalone function, or a method inside the Supermarket class? – John Gordon Jun 24 '22 at 00:39
  • a method inside the supermarket class :) – Paige Jun 24 '22 at 00:42
  • Are your indentions in your question exactly the same as they are in your code? Cause ur indents aren't lined up – TeddyBearSuicide Jun 24 '22 at 00:47
  • Welcome to Stack Overflow. Please read [ask] and the [formatting help](https://stackoverflow.com/help/formatting), and make sure your code appears with the exact indentation that your own code actually has. Please also read [mre] and try to show only the code *that is needed to reproduce the problem*. For example, does the problem still occur if `Menu` doesn't actually do anything? I think it will, because the problem that you describe has to do with *calling `Menu` in the first place* - if you can't call it properly, then it doesn't matter what is written there, right? – Karl Knechtel Jun 24 '22 at 01:04
  • Finally: please use tags to communicate about the *problem you have encountered* and thus the *question you are asking* - **not** about the overall task you want the code to perform. An expert in menus (if there even is such a thing) does not have any special advantage in answering the question; an expert in classes and type errors does. – Karl Knechtel Jun 24 '22 at 01:06

1 Answers1

0

To call the methods of a class, you have to create an object of that class first.

So in the end, instead of doing Menu()

supermarket = SupermarketDAO()
supermarket.Menu()