简单python菜单-缺失Self



TypeError: Menu()缺少1个必需的位置参数:" self "

我把self.Menu()放在init课上还有错误,我也试过放自己。Menu = Menu()和相同的错误问题。我需要在菜单中使用self来调用其他类。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()

要调用类的方法,必须首先创建该类的对象。

所以最后,我们不做Menu()

supermarket = SupermarketDAO()
supermarket.Menu()

最新更新