Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

simple python menu – missing Self

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()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading