CONFIG Module
This module contains the decorators and the definition of useful variables that are imported by the __init__ script.
- class klassez.config.XtermColors(dic_xcolor)[source]
Bases:
objectContainer for the pretty customization of printed text, in terms of colors and style. Uses the xterm version of the standard matplotlib colors.
Usage:
from klassez import textcolor text = 'my text' print(textcolor(text, 'red')
Use
print(klassez.textcolor)
to see the supported colors and styles.
- Attributes:
- colorsdict
Name of the supported colors and correspondant formatting string.
- stylesdict
Name of the supported font styles
- resetstr
String to reset the output to normal
Methods
__call__(text[, color, style])Formats the text.
- __call__(text: str, color=None, style=None)[source]
Formats the text.
- Parameters:
- textstr
Text to format
- color, cstr or None
Color to format the text. If
None, the default color is kept- style, sstr or None
Style to format the text. If
None, the default style is kept
- Returns:
- fmt_textstr
Formatted text with chosen style and color
- klassez.config.cprint(*args, c=None, s=None, sep=' ', end='\n', file=None, flush=False)[source]
This function can override the default
print()function, allowing to format the text easily. Callsklassez.textcolor()withcolor=candstyle=s.- Parameters:
- argssequence
Things to print, will be converted in text.
- cstr or None
Color of the text
- sstr or None
Style of the text
- All the rest are the parameters of the print function
- klassez.config.safe_kws(f)[source]
Decorator.
Let us assume we want to run the following code:
def f(a, b=1): print(a, b) kws = {'a': 1, 'b': 2, 'c': 3} f(**kws)
This will raise an error, because there is not a parameter
cin the signature off. Decoratingfwith@safe_kwswill filter the passedkwsdictionary to include only the parameters that are also present inf, in order to avoid this error to appear.