(etype, value)
return lines
Format the exception part of a traceback.

    The arguments are the exception type and value such as given by
    sys.last_type and sys.last_value. The return value is a list of
    strings, each ending in a newline.

    Normally, the list contains a single string; however, for
    SyntaxError exceptions, it contains several lines that (when
    printed) display detailed information about where the syntax
    error occurred.

    The message indicating which exception occurred is always the last
    string in the list.
Format the exception part of a traceback.
Format the exception part of a traceback .
def format_exception_only(etype, value):
    """Format the exception part of a traceback.

    The arguments are the exception type and value such as given by
    sys.last_type and sys.last_value. The return value is a list of
    strings, each ending in a newline.

    Normally, the list contains a single string; however, for
    SyntaxError exceptions, it contains several lines that (when
    printed) display detailed information about where the syntax
    error occurred.

    The message indicating which exception occurred is always the last
    string in the list.

    """
    # Gracefully handle (the way Python 2.4 and earlier did) the case of
    # being called with (None, None).
    if etype is None:
        return [_format_final_exc_line(etype, value)]

    stype = etype.__name__
    smod = etype.__module__
    if smod not in ("__main__", "builtins"):
        stype = smod + '.' + stype

    if not issubclass(etype, SyntaxError):
        return [_format_final_exc_line(stype, value)]

    # It was a syntax error; show exactly where the problem was found.
    lines = []
    filename = value.filename or "<string>"
    lineno = str(value.lineno) or '?'
    lines.append('  File "%s", line %s\n' % (filename, lineno))
    badline = value.text
    offset = value.offset
    if badline is not None:
        lines.append('    %s\n' % badline.strip())
        if offset is not None:
            caretspace = badline.rstrip('\n')[:offset].lstrip()
            # non-space whitespace (likes tabs) must be kept for alignment
            caretspace = ((c.isspace() and c or ' ') for c in caretspace)
            # only three spaces to account for offset1 == pos 0
            lines.append('   %s^\n' % ''.join(caretspace))
    msg = value.msg or "<no detail available>"
    lines.append("%s: %s\n" % (stype, msg))
    return lines
def format_exception_only ( etype , value ) : # Gracefully handle (the way Python 2.4 and earlier did) the case of # being called with (None, None). if etype is None : return [ _format_final_exc_line ( etype , value ) ] stype = etype . __name__ smod = etype . __module__ if smod not in ( "__main__" , "builtins" ) : stype = smod + '.' + stype if not issubclass ( etype , SyntaxError ) : return [ _format_final_exc_line ( stype , value ) ] # It was a syntax error; show exactly where the problem was found. lines = [ ] filename = value . filename or "<string>" lineno = str ( value . lineno ) or '?' lines . append ( '  File "%s", line %s\n' % ( filename , lineno ) ) badline = value . text offset = value . offset if badline is not None : lines . append ( '    %s\n' % badline . strip ( ) ) if offset is not None : caretspace = badline . rstrip ( '\n' ) [ : offset ] . lstrip ( ) # non-space whitespace (likes tabs) must be kept for alignment caretspace = ( ( c . isspace ( ) and c or ' ' ) for c in caretspace ) # only three spaces to account for offset1 == pos 0 lines . append ( '   %s^\n' % '' . join ( caretspace ) ) msg = value . msg or "<no detail available>" lines . append ( "%s: %s\n" % ( stype , msg ) ) return lines