-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added dod_print method. Coverage is now 85% (#74)
* Added dod_print method. Coverage is now 85% * Added dod documentation * Added dod documentation
- Loading branch information
Showing
5 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
jupytext: | ||
formats: md:myst | ||
text_representation: | ||
extension: .md | ||
format_name: myst | ||
format_version: 0.13 | ||
jupytext_version: 1.11.5 | ||
kernelspec: | ||
display_name: Python 3 | ||
language: python | ||
name: python3 | ||
--- | ||
|
||
# DOD | ||
|
||
## dod_print | ||
|
||
Prints in console a dictionary of nested dictionaries nicely | ||
|
||
```{code-cell} | ||
from pydicts import dod | ||
from datetime import date, datetime | ||
from decimal import Decimal | ||
d={"a": datetime.now(), "b": date.today(), "c": Decimal('12.32'), "d": None, "e": int(12), "f":None, "g":True, "h":False, "nested": {"x":1, "y":2, "z":{"n":4, "m":5, "o":6}}} | ||
dod_={} | ||
dod_["first"]=d | ||
dod_["second"]=d | ||
dod.dod_print(dod_) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from gettext import translation | ||
from importlib.resources import files | ||
from pprint import PrettyPrinter | ||
|
||
try: | ||
t=translation('pydicts', files("pydicts") / 'locale') | ||
_=t.gettext | ||
except: | ||
_=str | ||
|
||
def dod_print(dod_, indent=4, depth=None, width=80, sort_dicts=True): | ||
""" | ||
Make a nice print of a dictionary of nested dictionaries | ||
""" | ||
pp=PrettyPrinter(indent=4, compact=False, depth=None, width=width, sort_dicts=sort_dicts) | ||
pp.pprint(dod_) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from datetime import datetime, date | ||
from decimal import Decimal | ||
from pydicts import dod | ||
from pytest import fixture | ||
|
||
empty_lod=[] | ||
|
||
@fixture(autouse=True) | ||
def reload_lod_(): | ||
d={"a": datetime.now(), "b": date.today(), "c": Decimal('12.32'), "d": None, "e": int(12), "f":None, "g":True, "h":False, "nested": {"x":1, "y":2, "z":{"n":4, "m":5, "o":6}}} | ||
global dod_ | ||
dod_={} | ||
dod_["first"]=d | ||
dod_["second"]=d | ||
|
||
|
||
def test_dod_print(): | ||
dod.dod_print(dod_) |