Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python get line number of error

import sys, os

try:
    raise NotImplementedError("No error")
except Exception as e:
    exc_type, exc_obj, exc_tb = sys.exc_info()
    fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
    print(exc_type, fname, exc_tb.tb_lineno)
Comment

exception get line number python

import traceback

try:
    print(4/0)
except ZeroDivisionError:
    print(traceback.format_exc())
Comment

PREVIOUS NEXT
Code Example
Python :: conda create environment 
Python :: copy text to clipboard python 
Python :: how to check sklearn version in cmd 
Python :: python upgrade pip scipy 
Python :: how to make a python program to convert inch into cm 
Python :: how to print a list without brackets and commas python 
Python :: python for file in dir 
Python :: ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost) 
Python :: validation split python 
Python :: use incognito mode in selenium webdriver 
Python :: django admin create superuser 
Python :: how to make print float value without scientific notation in dataframe in jupyter notebook 
Python :: pycache in gitignore 
Python :: start a simple http server python3 
Python :: python click on screen 
Python :: flask delete cookie stackoverflow 
Python :: export image python 
Python :: get the torch version 
Python :: how to find the longest string in a list in python 
Python :: how to program 
Python :: subtract one hour from datetime python 
Python :: pd.options.display.max_columns()pd.options.display.max_row() 
Python :: working directory python 
Python :: pandas add index 
Python :: degree symbol in python 
Python :: xlim python 
Python :: how to import csv in pandas 
Python :: cmd run ps1 file in background 
Python :: python bytes to dict 
Python :: pandas save without index 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =