Python Exception Message Escaping <=> character

Question:

My colleagues and I are working on some code to produce SQL merge strings for users of a library we’re building in Python to be run in the Azure Databricks environment. These functions provide the SQL string through a custom exception that we’ve written called DebugMode. The issue that we’ve encountered and I can’t find a satisfactory answer to is why when the DebugMode string is printed do the <=> characters get removed? This can be replicated with a simpler example below where I’ve tossed various items into the Exception string to see what would get printed and what wouldn’t.

raise Exception('this is a string with the dreaded spaceship <=> < > <= >= `<=>` - = + / <random> <rand2>')

This snippet results in the following:
result of raised exception

What I don’t understand is why the <=> character is missing in the Exception printout at the top but is present when you expand the Exception. Is there a way to get the first string to include the <=> character?


I’ve also included the custom DebugMode class we’re using.

class DebugMode(Exception):
  '''
  Exception raised in the event of debug mode being enabled on any of the merge functions. It is intended to halt the merge and provide
  the SQL merge string for manual review.
  
  Attributes:
    sql_string (str): The sql merge string produced by the merge function.
    
  Methods:
    None
  '''
  def __init__(self, sql_string, message='Debug mode was enabled, the SQL operation has halted to allow manual review of the SQL string below.'):
    self.sql_string = sql_string
    self.message = message
    super().__init__(self.message) # overwrite the Exception base classe's message
    
  def __str__(self):
    return f'{self.message}n{self.sql_string}'
Asked By: Foxhound013

||

Answers:

Just providing a follow up for anyone who runs into the same thing. This was a Databricks notebook specific issue. @user2357112 had indicated, this was a problem where Databricks was parsing the html and had reserved the notation <some key work> for specific purposes (you can see some of these keywords and how they’re using them here: https://docs.databricks.com/error-messages/index.html).

As @tdelaney noted, this isn’t an issue in Jupyter notebooks or the python shell.

Answered By: Foxhound013
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.