Python Forum
log.exception() without arguments in old Python versions?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
log.exception() without arguments in old Python versions?
#1
Question 
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?
Reply
#2
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.
Reply
#3
(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?
Reply
#4
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.
Reply
#5
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.
cthart likes this post
Reply
#6
Why not add an empty message to the call?
_log.exception('')
cthart likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems passing arguments containing spaces to bash script and then on to python kaustin 6 414 Apr-03-2024, 08:26 PM
Last Post: deanhystad
  Python Launcher (on Windows) only necessary when 2 or more Python versions installed? pstein 1 332 Feb-17-2024, 12:43 PM
Last Post: deanhystad
  How do I handle escape character in parameter arguments in Python? JKR 6 1,176 Sep-12-2023, 03:00 AM
Last Post: Apoed2023
  Python versions with libexpat fixes raghupcr 5 2,540 Feb-24-2022, 06:26 PM
Last Post: raghupcr
  Installed versions of Python SamHobbs 5 2,540 Sep-02-2021, 02:28 PM
Last Post: jefsummers
  Different versions of Python3 and Python Led_Zeppelin 2 2,330 Jun-16-2021, 05:31 AM
Last Post: snippsat
  Python Versions ThatTamyBot 2 2,695 Mar-11-2021, 11:27 AM
Last Post: ThatTamyBot
  I seem to have two versions of python 3.7.9 installed miner_tom 7 4,482 Nov-22-2020, 06:42 PM
Last Post: miner_tom
  code with exception arguments doen't work MaartenRo 1 1,963 Aug-09-2020, 06:06 AM
Last Post: Gribouillis
  Exception handling in regex using python ShruthiLS 1 2,370 May-04-2020, 08:12 AM
Last Post: anbu23

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020