我想在函数中使用函数,但我得到错误我想获取上一个对象、当前对象和下一个对象我如何定义任何人都可以帮助我?实际上我是编程新手提前谢谢你
class DataHandler:
def previous_and_next(some_iterable):
prevs, items, nexts = tee(some_iterable, 3)
prevs = chain([None], prevs)
nexts = chain(islice(nexts, 1, None), [None])
return zip(prevs, items, nexts)
def current_obj(self):
print("The current object is : ",employee_list[0])
def next_obj(se):
property = previous_and_next(employee_list)
for previous, item, nxt in property:
print("Item is now", item, "next is", nxt, "previous is", previous)
employee_list = []
n = int(input("Enter number of Employee you want to add:"))
for i in range(n):
fname = input("Enter First name : ")
lname = input("Enter Last name : ")
emp_type = input("Enter Employee type : ")
details = [fname,lname,emp_type]
print(details)
employee_list.append(details)
obj = DataHandler()
obj.current_obj()
obj.next_obj()
我收到错误:property = previous_and_next(employee_list) NameError: name 'previous_and_next' is not defined