Python Forum
log.exception() without arguments in old Python versions? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: log.exception() without arguments in old Python versions? (/thread-38743.html)



log.exception() without arguments in old Python versions? - cthart - Nov-18-2022

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?


RE: log.exception() without arguments in old Python versions? - Larz60+ - Nov-19-2022

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.


RE: log.exception() without arguments in old Python versions? - cthart - Nov-19-2022

(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?


RE: log.exception() without arguments in old Python versions? - cthart - Nov-19-2022

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/module-logging.html

So either this code has never worked or it was changed later.


RE: log.exception() without arguments in old Python versions? - bowlofred - Nov-19-2022

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.


RE: log.exception() without arguments in old Python versions? - Gribouillis - Nov-19-2022

Why not add an empty message to the call?
_log.exception('')