object = \
unit/
├── mocks
├── plugins
│ ├── ast
│ ├── editor
│ ├── editor-autosuggest
│ ├── editor-metadata
│ ├── json-schema-validator
│ │ └── test-documents
│ └── validate-semantic
│ ├── 2and3
│ ├── bugs
│ └── oas3
└── standalone
└── topbar-insert
Of course I am aware of indent (json.dumps()) and pprint, and they are
OK options for my need. It's just that the compact, improved
visualization would be nice to have. Not so nice that I would go out of
my way to build, but nice enough to use an exising package.
def display_( object, last ):
directory = object; result = ''; count = len( directory )
for entry in directory:
count -= 1; name = entry; indent = ''
for c in last[ 1: ]: indent += '│ ' if c else ' '
indent += '├──' if count else '└──' if last else ''
result += '\n' + indent +( ' ' if indent else '' )+ name
if directory[ entry ]:
result += display_( directory[ entry ], last +[ count ])
return result
ram@zedat.fu-berlin.de (Stefan Ram) writes:
def display_( object, last ):
directory = object; result = ''; count = len( directory )
for entry in directory:
count -= 1; name = entry; indent = ''
for c in last[ 1: ]: indent += '│ ' if c else ' '
indent += '├──' if count else '└──' if last else ''
result += '\n' + indent +( ' ' if indent else '' )+ name
if directory[ entry ]:
result += display_( directory[ entry ], last +[ count ])
return result
This ultimate version has some variable names made more speaking:
def display_( directory, container_counts ):
result = ''; count = len( directory )
for name in directory:
count -= 1; indent = ''
for container_count in container_counts[ 1: ]:
indent += '│ ' if container_count else ' '
indent += '├──' if count else '└──' if container_counts else ''
result += '\n' + indent +( ' ' if indent else '' )+ name
if directory[ name ]:
result += display_\
( directory[ name ], container_counts +[ count ])
return result
I have a question that is a bit of a shot in the dark. I have this nice
bash utility installed:
$ tree -d unit/
unit/
├── mocks
├── plugins
│ ├── ast
│ ├── editor
│ ├── editor-autosuggest
│ ├── editor-metadata
│ ├── json-schema-validator
│ │ └── test-documents
│ └── validate-semantic
│ ├── 2and3
│ ├── bugs
│ └── oas3
└── standalone
└── topbar-insert
I just thought that it would be great if there was a Python utility that visualized a similar graph for nested data structures.
Of course I am aware of indent (json.dumps()) and pprint, and they are
OK options for my need. It's just that the compact, improved
visualization would be nice to have. Not so nice that I would go out of
my way to build, but nice enough to use an exising package.
What is the robust way to use Python to read in an XML and turn it into a >JSON file?
JSON dictionary is actually a tree. It is much easier to manage the >tree-structured data.
What is the robust way to use Python to read in an XML and turn it into
a JSON file?
JSON dictionary is actually a tree. It is much easier to manage the tree-structured data.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 54:36:28 |
Calls: | 10,397 |
Calls today: | 5 |
Files: | 14,067 |
Messages: | 6,417,416 |
Posted today: | 1 |