def format_exception_cut_frames(x=1):
 (typ, val, tb) = sys.exc_info()
 res = []
 tbres = traceback.format_tb(tb)
 res += tbres[(- x):]
 res += traceback.format_exception_only(typ, val)
 return ''.join(res)

def format_exception_cut_frames ( x = 1 ) : ( typ , val , tb ) = sys . exc_info ( ) res = [ ] tbres = traceback . format_tb ( tb ) res += tbres [ ( - x ) : ] res += traceback . format_exception_only ( typ , val ) return '' . join ( res )
format an exception with traceback .