smpl.debug

Simplified python debuging.

file(key, value[, level, times, seperator, ...])

Prints the message msg if level > debug_level to file filename.

file1(_key, _value[, level, times, _back])

Just like file() but times set to 1.

get_line_number_file([split, _back])

Gets the current filename and the current linenumber within it.

msg(msg[, tag, level, times, line_, _back])

Prints the message msg if level > debug_level and always returns the msg.

msg1(_msg[, tag, level, times, line_, _back])

Just like msg() but times set to 1.

once([_back])

Returns true only one time

table(key, value[, level, times, seperator, ...])

Saves key:value in filename.

table_flush_header([filename, seperator])

Saves the current keys from table() to filename.

table_flush_line([filename, seperator])

Saves the current values from table() to filename

Functions

smpl.debug.file(key, value, level=0, times=-1, seperator=';', _print=True, _back=0, filename='debug.csv')[source]

Prints the message msg if level > debug_level to file filename.

smpl.debug.file1(_key, _value, level=0, times=1, _back=0, **kwargs)[source]

Just like file() but times set 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 msg if 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() but times set 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:value in filename.

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;
smpl.debug.table_flush_header(filename='debug_table.csv', seperator=';')[source]

Saves the current keys from table() to filename.

smpl.debug.table_flush_line(filename='debug_table.csv', seperator=';')[source]

Saves the current values from table() to filename