Python Forum

Full Version: log.exception() without arguments in old Python versions?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have inherited some very old Python code:

import logging
_log = logging.getLogger('blah')
and later:

try:
   <snip>
except:
   _log.exception()
This call to exception() without arguments fails on Python 2.7 (the oldest version I have available to me) and 3.10 (which I'm targeting).

Was this syntax supported in a really old version of Python? If so, with what should I replace it now to get the same semantics?
you can try and run the enire code through 2to3
which is an Automated python 2.x to 3.x converter.
see: https://docs.python.org/3/library/2to3.html in python 3.11 documetation.
(Nov-19-2022, 02:18 AM)Larz60+ Wrote: [ -> ]you can try and run the enire code through 2to3
which is an Automated python 2.x to 3.x converter.
see: https://docs.python.org/3/library/2to3.html in python 3.11 documetation.

Sorry, but this answer is of no help to me.
  1. The problem occurs on Python 2.7, not just 3.x. NB This is a really old code base; it was written over 16 years ago (checked in to CVS(!) October 6 2006). I'm asking about really old versions of Python, probably 2.2, but definitely older than 2.5
  2. The 2to3 converter does nothing with these constructs. In fact, the only thing it recognises as needing changing is the print statement.

Anyone else any insights into semantics of old versions of Python? Can I run them online somewhere?
OK, after a bit of Googling I found the documentation for old versions of Python. The logging library was introduced in Python 2.3, and at least one parameter was always required to debug(), info(), exception(), etc: https://docs.python.org/release/2.3/lib/...gging.html

So either this code has never worked or it was changed later.
I suppose it was slightly possible that this originally had some undocumented behavior that was later "fixed" to match the documentation. But that doesn't seem to be true either. I ran it on Python 2.3 and it produces the same error.
Why not add an empty message to the call?
_log.exception('')