How can catch the error caused by a module variable not being set when the function is called
so example i have this code
file = "whatever the file path is"
menu= [] #this is a global variable
def ordermenu():
with open(file) as f: # read file
reader = csv.reader(f, delimiter=",")
next(reader, None) #skip the header
def showmenu():
for i in range(len(menu)):
print(menu)
ordermenu()
showmenu()
In this function i need to catch the error.
NOTE: i won't be using those global variable as parameters.
ordermenudidn't add anything tomenusoshowmenuhas nothing to do. You could just checkif len(menu) == 0in that function.