(self, filename=None)
Display the syntax error that just occurred.

        This doesn't display a stack trace because there isn't one.

        If a filename is given, it is stuffed in the exception instead
        of what was there before (because Python's parser always uses
        "<string>" when reading from a string).

        The output is written by self.write(), below.
Display the syntax error that just occurred.
Display the syntax error that just occurred .
def showsyntaxerror(self, filename=None):
        """Display the syntax error that just occurred.

        This doesn't display a stack trace because there isn't one.

        If a filename is given, it is stuffed in the exception instead
        of what was there before (because Python's parser always uses
        "<string>" when reading from a string).

        The output is written by self.write(), below.

        """
        type, value, tb = sys.exc_info()
        sys.last_type = type
        sys.last_value = value
        sys.last_traceback = tb
        if filename and type is SyntaxError:
            # Work hard to stuff the correct filename in the exception
            try:
                msg, (dummy_filename, lineno, offset, line) = value.args
            except ValueError:
                # Not the format we expect; leave it alone
                pass
            else:
                # Stuff in the right filename
                value = SyntaxError(msg, (filename, lineno, offset, line))
                sys.last_value = value
        if sys.excepthook is sys.__excepthook__:
            lines = traceback.format_exception_only(type, value)
            self.write(''.join(lines))
        else:
            # If someone has set sys.excepthook, we let that take precedence
            # over self.write
            sys.excepthook(type, value, tb)
def showsyntaxerror ( self , filename = None ) : type , value , tb = sys . exc_info ( ) sys . last_type = type sys . last_value = value sys . last_traceback = tb if filename and type is SyntaxError : # Work hard to stuff the correct filename in the exception try : msg , ( dummy_filename , lineno , offset , line ) = value . args except ValueError : # Not the format we expect; leave it alone pass else : # Stuff in the right filename value = SyntaxError ( msg , ( filename , lineno , offset , line ) ) sys . last_value = value if sys . excepthook is sys . __excepthook__ : lines = traceback . format_exception_only ( type , value ) self . write ( '' . join ( lines ) ) else : # If someone has set sys.excepthook, we let that take precedence # over self.write sys . excepthook ( type , value , tb )