本人python初学乍练,帮小弟我看看try except finally如何是这个么流程
本人python初学乍练,帮我看看try except finally怎么是这个么流程啊
上面那个方法我设想的是每次执行输出4条日志,整个程序产生36条日志,可是结果产生了很多日志,似乎每执行一次日志就多一条出来
####1####START####
####try####
####Exception####
####1####END####
####1####START####
####1####START####
####try####
####try####
####Exception####
####Exception####
####1####END####
####1####END####
####1####START####
####1####START####
####1####START####
####try####
####try####
####try####
####Exception####
####Exception####
####Exception####
####1####END####
####1####END####
####1####END####
####2####START####
####2####START####
####2####START####
####2####START####
####try####
####try####
####try####
####try####
####Exception####
####Exception####
####Exception####
####Exception####
####2####END####
####2####END####
####2####END####
####2####END####
####2####START####
####2####START####
####2####START####
####2####START####
####2####START####
####try####
####try####
####try####
####try####
####try####
####Exception####
####Exception####
####Exception####
####Exception####
####Exception####
####2####END####
####2####END####
####2####END####
####2####END####
####2####END####
####2####START####
####2####START####
####2####START####
####2####START####
####2####START####
####2####START####
####try####
####try####
####try####
####try####
####try####
####try####
####Exception####
####Exception####
####Exception####
####Exception####
####Exception####
####Exception####
####2####END####
####2####END####
####2####END####
####2####END####
####2####END####
####2####END####
####3####START####
####3####START####
####3####START####
####3####START####
####3####START####
####3####START####
####3####START####
####try####
####try####
####try####
####try####
####try####
####try####
####try####
####Exception####
####Exception####
####Exception####
####Exception####
####Exception####
####Exception####
####Exception####
####3####END####
####3####END####
####3####END####
####3####END####
####3####END####
####3####END####
####3####END####
####3####START####
####3####START####
####3####START####
####3####START####
####3####START####
####3####START####
####3####START####
####3####START####
####try####
####try####
####try####
####try####
####try####
####try####
####try####
import logging
def f(ids,message):
logger = logging.getLogger()
hdlr = logging.FileHandler("log.txt")
logger.addHandler(hdlr)
logger.setLevel(logging.NOTSET)
logger.info("####"+'%d'%ids+"####START####")
try:
logger.info("####try####")
x = int("##")
except Exception as e:
logger.info("####Exception####")
finally:
logger.info("####"+'%d'%ids+"####END####")
ids={1,2,3}
mess={"一","二","三"}
for i in ids:
for m in mess:
f(i,m)
上面那个方法我设想的是每次执行输出4条日志,整个程序产生36条日志,可是结果产生了很多日志,似乎每执行一次日志就多一条出来
####1####START####
####try####
####Exception####
####1####END####
####1####START####
####1####START####
####try####
####try####
####Exception####
####Exception####
####1####END####
####1####END####
####1####START####
####1####START####
####1####START####
####try####
####try####
####try####
####Exception####
####Exception####
####Exception####
####1####END####
####1####END####
####1####END####
####2####START####
####2####START####
####2####START####
####2####START####
####try####
####try####
####try####
####try####
####Exception####
####Exception####
####Exception####
####Exception####
####2####END####
####2####END####
####2####END####
####2####END####
####2####START####
####2####START####
####2####START####
####2####START####
####2####START####
####try####
####try####
####try####
####try####
####try####
####Exception####
####Exception####
####Exception####
####Exception####
####Exception####
####2####END####
####2####END####
####2####END####
####2####END####
####2####END####
####2####START####
####2####START####
####2####START####
####2####START####
####2####START####
####2####START####
####try####
####try####
####try####
####try####
####try####
####try####
####Exception####
####Exception####
####Exception####
####Exception####
####Exception####
####Exception####
####2####END####
####2####END####
####2####END####
####2####END####
####2####END####
####2####END####
####3####START####
####3####START####
####3####START####
####3####START####
####3####START####
####3####START####
####3####START####
####try####
####try####
####try####
####try####
####try####
####try####
####try####
####Exception####
####Exception####
####Exception####
####Exception####
####Exception####
####Exception####
####Exception####
####3####END####
####3####END####
####3####END####
####3####END####
####3####END####
####3####END####
####3####END####
####3####START####
####3####START####
####3####START####
####3####START####
####3####START####
####3####START####
####3####START####
####3####START####
####try####
####try####
####try####
####try####
####try####
####try####
####try####