I've been getting this error NameError: name 'filep' is not defined i need to make filep as a file path. but every time i run my code i always get this error.
i need to make the filep as a module variable instead of a parameter as well as menulist.
import csv
filep= # filepath
menulist = [] #global scope
def menu_List():
global menulist
menulist = [] # store items
try:
with open(filep) as f: # read file
reader = f.readlines()
next(reader, None) #skip the header
for row in reader:
row[2] = int(row[2].strip()) #convert string to int
row[1] = float(row[1].strip()) #convert string to float
if row[2] > 100 and row[2] < 200:
menulist.append(row)
except NameError:
raise ValueError("Variable not set")
menulist.sort(key=lambda x: x[-1])
menu_List()