主要一个装饰器只校验一个接口,扔类外面感觉太乱,试了几种方法,都不好使,直接上代码,这个是一个报错的写法静态方法不支持的说... TypeError: 'staticmethod' object is not callable
还有类方法也用过,不过好像也报错,直接用 self.还是报错,也不知道是不是我写错了
import datetime
class test():
# 时间校验
@staticmethod
def timeDecorator(fun):
timestart = datetime.datetime(today().year, today().month, today().day, 0, 0, 0)
orderend = datetime.datetime(func.today().year, func.today().month, func.today().day, 1, 0, 0)
timeend = datetime.datetime(today().year, today().month, today().day, 23, 59, 59)
orderstart = datetime.datetime(func.today().year, func.today().month, func.today().day, 23, 0, 0)
now = datetime.datetime.now()
def timeVerify(*args, **kwargs):
if (now > orderstart and now < timeend) or (now > timestart and now < orderend):
return print('系统维护中,23:00~01:00 无法使用,请于其他时间操作')
else:
return fun(*args, **kwargs)
return timeVerify
@timeDecorator
def prin(self):
print('pass')
return
test().prin()
还有类方法也用过,不过好像也报错,直接用 self.还是报错,也不知道是不是我写错了
import datetime
class test():
# 时间校验
@staticmethod
def timeDecorator(fun):
timestart = datetime.datetime(today().year, today().month, today().day, 0, 0, 0)
orderend = datetime.datetime(func.today().year, func.today().month, func.today().day, 1, 0, 0)
timeend = datetime.datetime(today().year, today().month, today().day, 23, 59, 59)
orderstart = datetime.datetime(func.today().year, func.today().month, func.today().day, 23, 0, 0)
now = datetime.datetime.now()
def timeVerify(*args, **kwargs):
if (now > orderstart and now < timeend) or (now > timestart and now < orderend):
return print('系统维护中,23:00~01:00 无法使用,请于其他时间操作')
else:
return fun(*args, **kwargs)
return timeVerify
@timeDecorator
def prin(self):
print('pass')
return
test().prin()
