项目作者: JarryShaw

项目描述 :
Python dict formatted dumper.
高级语言: Python
项目地址: git://github.com/JarryShaw/DictDumper.git
创建时间: 2018-03-05T13:09:49Z
项目社区:https://github.com/JarryShaw/DictDumper

开源协议:BSD 3-Clause "New" or "Revised" License

下载


DictDumper

  The dictdumper project is an open source Python program works as a stream formatted output dumper for dict.

  • About
    • dictdumper.Dumper
    • dictdumper.JSON
    • dictdumper.PLIST
    • dictdumper.Tree
    • dictdumper.XML
    • dictdumper.HTML
  • Installation
  • Usage

About

  Currently, it supports following formats —

  • dictdumper.Dumper — abstract base class of all dumpers
  • dictdumper.JSON — dump JavaScript object notation (JSON) format file
  • dictdumper.PLIST — dump Apple property list (PLIST) format file
  • dictdumper.Tree — dump tree-view text (TXT) format file
  • dictdumper.XML — dump extensible markup language (XML) file (base class)
  • dictdumper.HTML — dump JavaScript file under Vue.js framework (DEPRECATED)

Installation:

Note that dictdumper supports Python versions 2.7 and all versions since 3.0

  1. pip install dictdumper

Usage

dictdumper is quite easy to use. After installation, importation, and initialisation, you can simple call the instance to dump contents.

Take dictdumper.Tree for example

  1. import dictdumper
  2. dumper = dictdumper.Tree('out.txt')
  3. test_1 = dict(
  4. foo=-1,
  5. bar='Hello, world!',
  6. boo=dict(
  7. foo_again=True,
  8. bar_again=memoryview(b'bytes'),
  9. boo_again=None,
  10. ),
  11. )
  12. dumper(test_1, name='test_1')
  1. $ cat out.txt
  2. test_1
  3. |-- foo -> -1
  4. |-- bar -> Hello, world!
  5. |-- boo
  6. |-- foo_again -> True
  7. |-- bar_again
  8. | |-- type -> memoryview
  9. | |-- value -> 62 79 74 65 73
  10. | |-- text -> bytes
  11. |-- boo_again -> NIL
  1. import datetime
  2. test_2 = dict(
  3. foo=[1, 2.0, 3],
  4. bar=(1.0, bytearray(b'a long long bytes'), 3.0),
  5. boo=dict(
  6. foo_again=b'bytestring',
  7. bar_again=datetime.datetime(2020, 1, 31, 20, 15, 10, 163010),
  8. boo_again=float('-inf'),
  9. ),
  10. )
  11. dumper(test_2, name='test_2')
  1. $ cat out.txt
  2. test_1
  3. |-- foo -> -1
  4. |-- bar -> Hello, world!
  5. |-- boo
  6. |-- foo_again -> True
  7. |-- bar_again
  8. | |-- type -> memoryview
  9. | |-- value -> 62 79 74 65 73
  10. | |-- text -> bytes
  11. |-- boo_again -> NIL
  12. test_2
  13. |-- foo
  14. | |--> 1
  15. | |--> 2.0
  16. | |--> 3
  17. |-- bar
  18. | |-- type -> tuple
  19. | |-- value
  20. | |--> 1.0
  21. | |--> --
  22. | | |-- type -> bytearray
  23. | | |-- value
  24. | | | |--> 61 20 6c 6f 6e 67 20 6c 6f 6e 67 20 62 79 74 65
  25. | | | 73
  26. | | |-- text -> a long long bytes
  27. | |--> 3.0
  28. |-- boo
  29. |-- foo_again -> 62 79 74 65 73 74 72 69 6e 67
  30. |-- bar_again -> 2020-01-31T20:15:10.163010
  31. |-- boo_again -> -Infinity
  1. test_3 = dict(
  2. foo="stringstringstringstringstringstringstringstringstringstring",
  3. bar=[
  4. "s1", False, "s3",
  5. ],
  6. boo=[
  7. "s4", dict(s="5", j="5"), "s6"
  8. ],
  9. far=dict(
  10. far_foo=["s1", "s2", "s3"],
  11. far_var="s4",
  12. ),
  13. biu=float('nan'),
  14. )
  15. dumper(test_3, name='test_3')
  1. $ cat out.txt
  2. test_1
  3. |-- foo -> -1
  4. |-- bar -> Hello, world!
  5. |-- boo
  6. |-- foo_again -> True
  7. |-- bar_again
  8. | |-- type -> memoryview
  9. | |-- value -> 62 79 74 65 73
  10. | |-- text -> bytes
  11. |-- boo_again -> NIL
  12. test_2
  13. |-- foo
  14. | |--> 1
  15. | |--> 2.0
  16. | |--> 3
  17. |-- bar
  18. | |-- type -> tuple
  19. | |-- value
  20. | |--> 1.0
  21. | |--> --
  22. | | |-- type -> bytearray
  23. | | |-- value
  24. | | | |--> 61 20 6c 6f 6e 67 20 6c 6f 6e 67 20 62 79 74 65
  25. | | | 73
  26. | | |-- text -> a long long bytes
  27. | |--> 3.0
  28. |-- boo
  29. |-- foo_again -> 62 79 74 65 73 74 72 69 6e 67
  30. |-- bar_again -> 2020-01-31T20:15:10.163010
  31. |-- boo_again -> -Infinity
  32. test_3
  33. |-- foo
  34. | |--> stringstringstringstringstringstringstri
  35. | ngstringstringstring
  36. |-- bar
  37. | |--> s1
  38. | |--> False
  39. | |--> s3
  40. |-- boo
  41. | |--> s4
  42. | |--> --
  43. | | |-- s -> 5
  44. | | |-- j -> 5
  45. | |--> s6
  46. |-- far
  47. | |-- far_foo
  48. | | |--> s1
  49. | | |--> s2
  50. | | |--> s3
  51. | |-- far_var -> s4
  52. |-- biu -> NaN