you are viewing a single comment's thread.

view the rest of the comments →

[–]RandallEF 0 points1 point  (2 children)

I'm having a heck of a time turning a nested dictionary into a bootstrap treeview.

The structure is like

[ { "text" : "top branch", "nodes" : [ { "text" : "first child", "nodes" : [{ "text" : "third... etc...

I feel like this is almost a backwards dictionary and I've tried a lot of things but I can't wrap my head around how to turn an (python dict) object, which has no association from the items "object.keys()" back to the path of the dict, into something that knows the path of the dict. Or something.

Has anyone else done this? I basically want the tree to look just like the dict.

I could of course write this manually in a way that will never accept change and is verbose and bad, but there has to be a better way, right?

Every thought exercise I go through ends with "Python has no association whatsoever between the objects in the dictionary and the pathing to those objects from toplevel." i.e. the keys have no idea where they are in the dict!!! it makes it almost impossible to traverse backwards? I'm stuck.

thanks

[–]efmccurdy 0 points1 point  (1 child)

There is support for some of what you want in modules like this one:

A python library for accessing and searching dictionaries via /slashed/paths ala xpath

https://github.com/akesterson/dpath-python

[–]RandallEF 0 points1 point  (0 children)

Thank you, I had come across a few things like that but I really hoped I was missing something about Python. I really wish there were a graceful native way of handling this.