def print_exception(etype, value, tb, limit=None, file=None, chain=True):
import traceback<EOL>if file is None:<EOL><INDENT>file = sys.stderr<EOL><DEDENT>if tb:<EOL><INDENT>file.write('<STR_LIT>')<EOL>print_tb(tb, limit, file)<EOL><DEDENT>lines = traceback.format_exception_only(etype, value)<EOL>for line in lines:<EOL><INDENT>file.write(line)<EOL><DEDENT>
Print exception up to 'limit' stack trace entries from 'tb' to 'file'.

    This differs from print_tb() in the following ways: (1) if
    traceback is not None, it prints a header "Traceback (most recent
    call last):"; (2) it prints the exception type and value after the
    stack trace; (3) if type is SyntaxError and value has the
    appropriate format, it prints the line where the syntax error
    occurred with a caret on the next line indicating the approximate
    position of the error.