report.py蟒装饰器未服用从恒定传递的值
if __name__ == "__main__":
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description = "CHECK-ACCESS REPORTING.")
parser.add_argument('--input','-i', help='Filepath containing the Active Directory userlist')
parser.add_argument('--timestamp', '-t', nargs='?',const="BLANK", help='filepath with environement varible set')
args, unknownargs = parser.parse_known_args(sys.argv[1:])
timestampchecker(args.timestamp)
#checking the value of cons.DISPLAYRESULT is TRUE
main()
timestampchecker功能:
该功能检查用户是否已经设置了-t参数。如果设置了,我已经定义了一个叫做cons.DISPLAYRESULT的常量为true。
该函数运行良好,并将常量值设置为True。 但在主要功能我已经实现了这个装饰它没有采取真正的价值,但假
timer.py
def benchmarking(timestaus):
def wrapper(funct):
def timercheck(*args, **kwarg):
if timestaus is True:
starttime=time.time()
funct(*args, **kwarg)
if timestaus is True:
print('Time Taken:',round(time.time()-starttime, 4))
return timercheck
return wrapper
我装饰了一些方法,在报告的main()方法.py与上面的装饰器。例如,这是在report.py正在使用的类并且与上述装饰饰
class NotAccountedReport:
def __init__(self, pluginoutputpath):
""" Path where the plugins result are stored need these files"""
self.pluginoutputpath = pluginoutputpath
@benchmarking(cons.DISPLAY_TIME_STAMP)
def makeNotAccountableReport():
#some functionality
这里我已通过恒定值,其 时虽然称为前测试的参数装饰被转换为True是采取虚假 ,因此装修未实施。问题出在哪里 找不出
这是一个无足轻重的问题,但也许我不理解你的最后一段。当你说“我已经将常数值传递给参数装饰器”时,你的意思是'@benchmarking(const)'?那么'const是True'和'bool(const)是True'将会有不同的结果。 –
我的意思是说我已经定义了常量,并且该值是装饰器正在传递的值。只有当该值设置为“True”时,装饰器才会运行。但是,发生了什么是认为常数值是真正的装饰者正在加载,并采取'False'而不是 –