Python Forum

Full Version: print name of def
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello. I would like to know if there is a way to derive the name of the function that has an exception.
I would like to better highlight through debugging which function is in exception. but writing the name of the function by hand is long and boring.

    def GUI_GetRGB(self, event):
        global CamOpen
        try:
            click_x = int(mouse_over.Mouse_X / (Frame_Width/Pixmap_width))
            click_y = int(mouse_over.Mouse_Y / (Frame_Width/Pixmap_width))
            if not (len(CamFram) == 0):
                self.GUI.TW_WORK.setItem(3, 1, QTableWidgetItem('{},{}' .format(click_x, click_y)))
                R, G, B = CamFram[-1][click_y, click_x]
                self.GUI.TW_WORK.setItem(4, 1, QTableWidgetItem('{},{},{}' .format(R, G, B)))

        except Exception as msg:
            logging.error('Error GUI_GetRGB: ' + str(msg))
The traceback gives you the information you need. To get that programmatically, see the traceback module (there are examples in there too).
(Feb-16-2020, 08:04 AM)ndc85430 Wrote: [ -> ]The traceback gives you the information you need. To get that programmatically, see the traceback module (there are examples in there too).

thanks! Smile