This is the code:
The reason I decided to use the sys.get_frame method to check the caller is because the remaining branch of the def_parser function is quite long and it seems very repetitive to create two separate ,long, and almost identical, functions just because the caller is different.
What have I missed here?
Thanks in advance
def date_parser(date): while True: try: checked_date = datetime.strptime(date,'%d %b %Y') caller = sys._getframe(1).f_code.co_name check = input(f"You have entered {checked_date}. Is this correct? y/n ") if check == 'y': print(caller) if caller == 'birth_date' or 'date_parser': if checked_date <= datetime.today(): return checked_date else: z = input("Cannot have date after today. Please re-enter date. ") return date_parser(z) break else: return checked_date .... def birth_date(date): return date_parser(date) def expiry_date(date): return date_parser(date) birth_date = birth_date("16 May 2023") expiry_date = expiry_date("26 Jun 2022")When the code is run, birth_date correctly runs the else loop (can't enter a birth date in the future) but expiry_date also runs the else loop. I (obviously) need the code to accept an expiry date into the future.
The reason I decided to use the sys.get_frame method to check the caller is because the remaining branch of the def_parser function is quite long and it seems very repetitive to create two separate ,long, and almost identical, functions just because the caller is different.
What have I missed here?
Thanks in advance