还可以考虑:def foo():
try:
foo.counter += 1
except AttributeError:
foo.counter = 1推理:大量丙酮(ask for forgiveness not permission)使用异常(只引发一次)而不是if分支(认为)止蚀例外情况)