import datetime class TimeException(Exception): def __init__(self, exception_info): super().__init__() self.info = exception_info def __str__(self): return self.info def time_check(func): def wrapper(*args, **kwargs): if datetime.datetime.now().year == 2020: func(*args, **kwargs) else: raise TimeException("函数已过时") return wrapper @time_check def test(name): print("Hello {}, 2021 Happy".format(name)) if __name__ == "__main__": test("backbp")