Python logging decorator exercise + debugging

I came across this article in my Feedly feed today, and it looked like a good exercise to work on to develop my understanding of logging and decorator practices in Python.

Retyping the examples in vim/sublime went fine, but when I went to run it with Python3 I got:

 

mikes-MacBook-Air:pythonscraps mike$ python3 testloggerdecorator.py
Traceback (most recent call last):
File “test
loggerdecorator.py”, line 9, in zerodivide() File “/Users/mike/repos/thecatchall/pythonscraps/exceptiondecor.py”, line 39, in wrapper raise RuntimeError: No active exception to reraise

 

Well that seems kind of peculiar. The article didn’t specify a Python version, and I couldn’t pick out any differences right away, so I ran it in Python2, and the correct “Divide by zero” behavior occurred. That’s what I was going for.

 

mikes-MacBook-Air:pythonscraps mike$ python testloggerdecorator.py
Traceback (most recent call last):
File “test
loggerdecorator.py”, line 9, in zerodivide() File “/Users/mike/repos/thecatchall/pythonscraps/exceptiondecor.py”, line 33, in wrapper return function(args, *kwargs) File “testloggerdecorator.py”, line 6, in zero_divide 1/0 ZeroDivisionError: integer division or modulo by zero

 

Hm. Decorators are pretty cool, and this exercise really helped me wrap my mind around them (pun intended?) so I need to get to the bottom of this.

 

It looks like it’s a difference in exception syntax between 2 and 3, so I’ll be back after running through this nice post.

Leave a Reply

Your email address will not be published. Required fields are marked *