Last active
March 9, 2021 14:47
-
-
Save jlinoff/c5d2fd19b756167ab475 to your computer and use it in GitHub Desktop.
Simple debug function that uses introspection to display the file name, function name and line number of the caller.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def debug(msg): | |
''' | |
Display a debug message with the file name, function | |
name and line number. | |
''' | |
import inspect | |
parent_frame = inspect.currentframe().f_back | |
lineno = parent_frame.f_lineno | |
fctname = parent_frame.f_code.co_name | |
filename = parent_frame.f_code.co_filename | |
sys.stderr.write('DEBUG:{}:{}:{} {}\n'.format(filename, fctname, lineno, msg)) | |
def fct1(): | |
''' | |
Dummy test function. | |
''' | |
debug('a debug message') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment