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.

  5 comments for “Python logging decorator exercise + debugging

  1. September 19, 2016 at 11:20 am

    I was waiting for this form of issue. Thank you very much for
    the location.

  2. September 19, 2016 at 5:47 pm

    This is a very great hints especially to those new to blogosphere, short and precise info…
    Thanks for sharing this one. A must read article.

  3. September 23, 2016 at 3:25 am

    This is an extremely good suggestions particularly to those new to blogosphere, short and precise info…
    Thanks for sharing this one. A must read article.

  4. September 23, 2016 at 5:44 pm

    Way cool, some valid points! I appreciate you making this
    post available, the rest of the website is also high quality.
    Have a enjoyable.

  5. September 23, 2016 at 8:10 pm

    Quite fine post, I definitely love this
    site, keep on it.

Leave a Reply

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