var_print
This package was inspired by icecream. Please check it out if you consider installing any variable printer. Similar to icecream you can print not only the variable value but the name as well.
At the same time the content gets nicely formated resulting in readable dictionaries, lists, tuples, sets, frozensets and generators even if they are nested.
As a neat finish the output is colored. By default the variable name is white, the value blue, dictionary keys are green, dictionary values are yellow and the syntax is white.
But you are not bound to this color scheme. There are a few stored in the color_schemes property of varpFore which you can choose from. But that's not the limit. You can choose the rgb code to customize the display.
Content
-
Installation
-
Usage
-
Normal usage
-
Options
-
-
Planned
Installation
pip install var-print
Usage
Normal usage
It's pretty simple nevertheless there are many options to dig into.
To use it as is simply call varp after importing it.
from var_print import varp
x = 1
varp(x)
# prints:
# x = 1
When calling varp with multiple arguments / variables they are handled one by one.
a, b = 1, 2
varp(a, b)
# prints:
# a = 1
# b = 2
Calling them as a tuple (or list) will make a single line out of it.
varp((a, b))
# prints:
# (a, b) = (1, 2)
For demonstration purposes, the following functions are included.
varp.show_current_color_preset()
Result:
varp.show_a_nested_dictionary()
Result:
varp.show_formating_of_different_types()
Result:
Options:
-
varp.coloredSet it to False to print without colors.
-
varp.deactivatedSet it to True to deactivate the output or call
varp.deactivate()/varp.activate() -
varp.name_value_sepSeperator for the variable name and the value. Default value is
' = '. -
varp.commaSeperator for the values of iterables. Default value is
', '. -
varp.prefixPrefix for all prints with varp. Default is
''(no prefix). -
varp.iter_items_per_lineWhen printing a list or other iterables, you may want to limit how many items can be printed on a line to improve readability. Default value is 10. Note that for better readability I chose to insert a line break after every closing dictionary, list, tuple, set, frozenset and generator.
-
varp.dict_items_per_lineShould be like
varp.iter_items_per_linebut I format the lenght of every key to the max lenght of all keys to achieve better readability when printing only one item per line so you need to setvarp.dict_alignmentto'none'to deactivate alignment. -
varp.dict_alignmentDefault value is
'left'but you might want to choose'right'or'none'. Keys and values are aligned as wished. If'none'is chosen there is no alignment. Also possible is a tuple containing to values, each beeing one of the mentioned three, to set the alignment for the key and the value seperately. -
varp.list_alignmentSame as
varp.dict_alignmentbut for lists, tuples, sets, frozensets and generators and only with one value of'left','right'or'none' -
varp.color_preset(preset)Getting different colors is as easy as calling
varp.color_presetwith the preset of your choice. There are a bunch of presets saved invarpFore.all_presets. Since every preset has the key 'name' you can choose a preset by name withvarpFore.get_preset_by_name(name). -
varp.show_all_color_presetsCalling this function will print out every color_preset saved in
varpFore.all_presets. -
varp.show_current_color_presetYou guessed it this shows you your current color preset.
-
varp.save_current_color_presetDon't like the available color presets? Save your own!
-
varp.varname_rgbr, g, b code for the variable name
-
varp.name_value_sep_rgbr, g, b code for the seperator of the variable naem and the value
-
varp.value_rgbr, g, b code for the value
-
varp.comma_rgbr, g, b code for the comma (or any varp.comma string)
-
varp.prefix_rgbr, g, b code for the prefix
-
varp.dict_keys_rgbr, g, b code for the dictionary keys
-
varp.dict_vals_rgbr, g, b code for dictionary values
Planned
I plan on adding different colors for different nesting levels and more formatting cases for numpy and what not.
There are problems fitting the output to the terminal but as soon as I have that figured out I will add it.
Release files for var-print 0.0.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| var_print-0.0.11.tar.gz | 17.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| var_print-0.0.11-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.5 kB
Release files / var_print-0.0.11.tar.gz
| Download URL | var_print-0.0.11.tar.gz |
|---|---|
| Size | 17.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac1e85c71d07dd03b1426ca2d9c98520af22d03b8e25be2dd6bed968eb3b0589
|
|
BLAKE2b-256 checksum How to use checksums |
28db2a2474fe5bbb5618add8c51e637b659116d8290f5ce7d12c0a6d02b099ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.14
|
Release files / var_print-0.0.11-py3-none-any.whl
| Download URL | var_print-0.0.11-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dfc163d296f65759b61a0daa73fa46aa4417734a6d6acde2271022b000f77ef3
|
|
BLAKE2b-256 checksum How to use checksums |
210e319370854a30643bb6d74de153094a593d9e2d1f93e774aad5b18c01eb28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.14
|