smpl.debug¶
Simplified python debuging.
|
Prints the message |
|
Just like |
|
Gets the current filename and the current linenumber within it. |
|
Prints the message |
|
Just like |
|
Returns true only one time |
|
Saves |
|
Saves the current keys from |
|
Saves the current values from |
Functions
- smpl.debug.file(key, value, level=0, times=-1, seperator=';', _print=True, _back=0, filename='debug.csv')[source]¶
Prints the message
msgif level > debug_level to filefilename.
- smpl.debug.file1(_key, _value, level=0, times=1, _back=0, **kwargs)[source]¶
Just like
file()buttimesset to 1.
- smpl.debug.get_line_number_file(split=True, _back=0)[source]¶
Gets the current filename and the current linenumber within it.
Parameters¶
- splitbool
Indicates whenever the folders above of the file should be included in the returned filename.
- _backint
Number of stack/frames to go back.
Returns¶
- filenumberint
First element in the return array
- filenamestr
Second element in the return array
Examples¶
>>> get_line_number_file() (1, '<doctest smpl.debug.debug.get_line_number_file[0]>') >>> for i in range(2): ... get_line_number_file() (2, '<doctest smpl.debug.debug.get_line_number_file[1]>') (2, '<doctest smpl.debug.debug.get_line_number_file[1]>')
- smpl.debug.msg(msg, tag='', level=0, times=-1, line_=False, _back=0, **kwargs)[source]¶
Prints the message
msgif level > debug_level and always returns the msg.Parameters¶
- tagstr
Sets a tag to be printed for the debug message.
- levelint
Debug level.
- timesint
How often should the message be printed if the function gets called multiple times (e.g. in a loop).
- _linebool
Print the current line in the python source.
- _backint
Number of stack/frames to go back.
Examples¶
>>> msg("hi", level = -9999) DBG::<doctest smpl.debug.debug.msg[0]>:1: hi 'hi' >>> msg("hi") 'hi'
- smpl.debug.msg1(_msg, tag='', level=0, times=1, line_=False, _back=0, **kwargs)[source]¶
Just like
msg()buttimesset to 1.Parameters¶
- tagstr
Sets a tag to be printed for the debug message.
- levelint
Debug level.
- timesint
How often should the message be printed if the function gets called multiple times (e.g. in a loop).
- _linebool
Print the current line in the python source.
- _backint
Number of stack/frames to go back.
Examples¶
>>> for i in range(-2,2): ... msg1(i, level = i) DBG::<doctest smpl.debug.debug.msg1[0]>:2: -2 -2 -1 0 1
- smpl.debug.once(_back=0)[source]¶
Returns true only one time
Examples¶
>>> for i in range(10): ... if once(): ... print(i) 0
- smpl.debug.table(key, value, level=0, times=-1, seperator=';', _print=False, _back=0, filename='debug_table.csv')[source]¶
Saves
key:valueinfilename.Examples¶
>>> for i in range(-2,2): ... table("a", i,level=-1) ... table("b", i**2,level=-1) ... table("c", i**i,level=-1) ... if once(): table_flush_header(); ... table_flush_line() -2 4 0.25 -1 1 -1.0 0 0 1 1 1 1 >>> from smpl import io >>> print(io.read("debug_table.csv").strip()) a;b;c; -2.000000000000000000000000000000e+00;4.000000000000000000000000000000e+00;2.500000000000000000000000000000e-01; -1.000000000000000000000000000000e+00;1.000000000000000000000000000000e+00;-1.000000000000000000000000000000e+00; 0.000000000000000000000000000000e+00;0.000000000000000000000000000000e+00;1.000000000000000000000000000000e+00; 1.000000000000000000000000000000e+00;1.000000000000000000000000000000e+00;1.000000000000000000000000000000e+00; >>> import pandas as pd >>> pd.read_csv("debug_table.csv") a;b;c; 0 -2.000000000000000000000000000000e+00;4.000000... 1 -1.000000000000000000000000000000e+00;1.000000... 2 0.000000000000000000000000000000e+00;0.0000000... 3 1.000000000000000000000000000000e+00;1.0000000... >>> reset_table() >>> io.write("debug_table.csv","") >>> for i in range(1,3): ... table("a", np.array([i*k for k in range(5)]),level=-1) ... table("b", np.array([i*i*k for k in range(5)]),level=-1) ... if once(): table_flush_header(); ... table_flush_line() array([0, 1, 2, 3, 4]) array([0, 1, 2, 3, 4]) array([0, 2, 4, 6, 8]) array([ 0, 4, 8, 12, 16]) >>> print(io.read("debug_table.csv").strip()) a;b; 0.000000000000000000000000000000e+00;0.000000000000000000000000000000e+00; 1.000000000000000000000000000000e+00;1.000000000000000000000000000000e+00; 2.000000000000000000000000000000e+00;2.000000000000000000000000000000e+00; 3.000000000000000000000000000000e+00;3.000000000000000000000000000000e+00; 4.000000000000000000000000000000e+00;4.000000000000000000000000000000e+00; 0.000000000000000000000000000000e+00;0.000000000000000000000000000000e+00; 2.000000000000000000000000000000e+00;4.000000000000000000000000000000e+00; 4.000000000000000000000000000000e+00;8.000000000000000000000000000000e+00; 6.000000000000000000000000000000e+00;1.200000000000000000000000000000e+01; 8.000000000000000000000000000000e+00;1.600000000000000000000000000000e+01;