嗨,我希望我的python脚本能打印分钟的日志,因此我希望替换变量 b ,但不会发生,并生成名称为%(b)s_python.log < / strong>
请帮助!
import logging, datetime
a=datetime.date.today()
b=a.strftime("%y_%B_%a_%H%M")
print(b)
logging.basicConfig(filename="D:\%(b)s_python.log",level=logging.DEBUG,format="%(levelname)s %(asctime)s-%(message)s")
logging.debug("Hi Sudhirrrrrrrrr")
答案 0 :(得分:1)
datetime.date.today()不能提供您当前的小时和分钟。
import logging, datetime
a=datetime.datetime.now()
b='D:\\'+a.strftime("%y_%B_%a_%H%M")+'s_python.log'
print(b)
logging.basicConfig(filename=b,level=logging.DEBUG,format="%(levelname)s %(asctime)s-%(message)s")
logging.debug("Hi Sudhirrrrrrrrr")