4. CUtils module¶
- PythonExtensionsCollection.Utils.CUtils.PrettyPrint(oData=None, hOutputFile=None, bToConsole=True, nIndent=0, sPrefix=None, bHexFormat=False)[source]¶
Function:
PrettyPrint
Wrapper function to create and use a
CTypePrintobject. This wrapper function is responsible for printing out the content to console and to a file (depending on input parameter).The content itself is prepared by the method
TypePrintof classCTypePrint. This happensPrettyPrintinternally.The idea behind the
PrettyPrintfunction is to resolve also the content of composite data types and provide for every parameter inside:the type
the total number of elements inside (e.g. the number of keys inside a dictionary)
the counter number of the current element
the value
Example call:
PrettyPrint(oData)(with oData is a Python variable of any type)The output can e.g. look like this:
[DICT] (3/1) > {K1} [STR] : 'Val1' [DICT] (3/2) > {K2} [LIST] (4/1) > [INT] : 1 [DICT] (3/2) > {K2} [LIST] (4/2) > [STR] : 'A' [DICT] (3/2) > {K2} [LIST] (4/3) > [INT] : 2 [DICT] (3/2) > {K2} [LIST] (4/4) > [TUPLE] (2/1) > [INT] : 9 [DICT] (3/2) > {K2} [LIST] (4/4) > [TUPLE] (2/2) > [STR] : 'Z' [DICT] (3/3) > {K3} [INT] : 5
Every line of output has to be interpreted strictly from left to right.
For example the meaning of the fifth line of output
[DICT] (3/2) > {K2} [LIST] (4/4) > [TUPLE] (2/1) > [INT] : 9is:
The type of input parameter (
oData) isdictThe dictionary contains 3 keys
The current line gives information about the second key of the dictionary
The name of the second key is ‘K2’
The value of the second key is of type
listThe list contains 4 elements
The current line gives information about the fourth element of the list
The fourth element of the list is of type
tupleThe tuple contains 2 elements
The current line gives information about the first element of the tuple
The first element of the tuple is of type
intand has the value 9
Types are encapsulated in square brackets, counter in round brackets and key names are encapsulated in curly brackets.
Args:
oData (any Python data type)
A variable of any Python data type.
hOutputFile (handle to a file opened for writing or appending; optional; default None)
If handle is not
Nonethe content is written to this file, otherwise not.bToConsole (bool; optional; default: True)
If
Truethe content is written to console, otherwise not.nIndent (int; optional; default: 0)
Sets the number of additional blanks at the beginning of every line of output (indentation).
sPrefix (str; optional; default: None)
Sets a prefix string that is added at the beginning of every line of output.
bHexFormat (bool; optional; default: False)
If
Truethe output is printed in hexadecimal format (but strings only).Returns:
listOutLines (list)
List of lines containing the prepared output