hprint 2.0.5__py3-none-any.whl → 2.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hprint/__init__.py CHANGED
@@ -24,10 +24,10 @@ def _pprint(obj):
24
24
 
25
25
  def json_print(data):
26
26
  if isinstance(data, dict):
27
- _print(json.dumps(data, indent=4, sort_keys=True))
27
+ _print(json.dumps(data, indent=4, sort_keys=True, default=str))
28
28
  elif isinstance(data, list):
29
29
  try:
30
- _print(json.dumps([dict(d) for d in data], indent=4, sort_keys=True))
30
+ _print(json.dumps([dict(d) for d in data], indent=4, sort_keys=True), default=str)
31
31
  except Exception:
32
32
  try:
33
33
  _pprint([dict(d) for d in data])
hprint/dsutils.py ADDED
@@ -0,0 +1,40 @@
1
+ from icecream import Source
2
+ import inspect
3
+
4
+
5
+ def flatten0(L):
6
+ if not isinstance(L, (list, tuple, set)):
7
+ yield L
8
+ return
9
+ for F in L:
10
+ yield from flatten(F)
11
+
12
+
13
+ def flatten(L):
14
+ return list(flatten0(L))
15
+
16
+
17
+ def kdict(*args, **kwargs):
18
+ """
19
+ create dict only by key
20
+
21
+ > a, b, c = 1, 2, 3
22
+ > d = kdict(a, b, c)
23
+ > d
24
+ > {'a': 1, 'b': 2, 'c': 3}
25
+
26
+ """
27
+ assert not kwargs, "kwargs not allowed"
28
+ callFrame = inspect.currentframe().f_back
29
+ callNode = Source.executing(callFrame).node
30
+ source = Source.for_frame(callFrame)
31
+ tokens = source.asttokens()
32
+ argStrs = [
33
+ tokens.get_text(node)
34
+ for node in callNode.args
35
+ ]
36
+ return dict(zip(argStrs, args))
37
+
38
+
39
+ def kvdict(*lst):
40
+ return dict(list(zip(lst, lst)))
hprint/utils.py ADDED
@@ -0,0 +1,11 @@
1
+ from functools import partial
2
+
3
+
4
+ def install_print_with_flush():
5
+ try:
6
+ builtins = __import__('__builtin__')
7
+ except ImportError:
8
+ builtins = __import__('builtins')
9
+
10
+ setattr(builtins, 'print0', print)
11
+ setattr(builtins, 'print', partial(print, flush=True))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hprint
3
- Version: 2.0.5
3
+ Version: 2.0.7
4
4
  Summary: Print python object in table/json format
5
5
  Home-page: https://github.com/ruanhao/hprint
6
6
  Author: Hao Ruan
@@ -0,0 +1,8 @@
1
+ hprint/__init__.py,sha256=3_P_hQrHKSF-5f1Zj4aFDimk-jeQv3XgthRYB7dU8V0,5230
2
+ hprint/dsutils.py,sha256=UD1L8-23_0320w7ESc_Vwc148w_CLSyJ6t7T5t3yu9M,786
3
+ hprint/utils.py,sha256=9yZ6uiE7DQSnQLNnpBuu-SyXsaGVs3EWnBepUJhZHtw,283
4
+ hprint-2.0.7.dist-info/LICENSE,sha256=5IASoCg1AtQddnqyVxltUyoadbZzUpRa_0QvUB-Hwlg,1065
5
+ hprint-2.0.7.dist-info/METADATA,sha256=qh9uSz_fjdim_hE8zqET3mGWs_o7fPyNKvP1LeLQTTs,5298
6
+ hprint-2.0.7.dist-info/WHEEL,sha256=5sUXSg9e4bi7lTLOHcm6QEYwO5TIF1TNbTSVFVjcJcc,92
7
+ hprint-2.0.7.dist-info/top_level.txt,sha256=yHUSDt5IDs8J8taLMOu-SaOZK24DyzM0TidniiEJ-Ng,7
8
+ hprint-2.0.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.40.0)
2
+ Generator: bdist_wheel (0.41.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,6 +0,0 @@
1
- hprint/__init__.py,sha256=oicJxWP69JCK_LQquban44ty2yAA4HWALdEJu3ShADQ,5204
2
- hprint-2.0.5.dist-info/LICENSE,sha256=5IASoCg1AtQddnqyVxltUyoadbZzUpRa_0QvUB-Hwlg,1065
3
- hprint-2.0.5.dist-info/METADATA,sha256=X828ivFl0Fl6MnAO0aT9jPEYp9k29NC3Hf0CPE8IUkw,5298
4
- hprint-2.0.5.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
5
- hprint-2.0.5.dist-info/top_level.txt,sha256=yHUSDt5IDs8J8taLMOu-SaOZK24DyzM0TidniiEJ-Ng,7
6
- hprint-2.0.5.dist-info/RECORD,,