How to pretty-print an OFX tree? #167
Replies: 2 comments 1 reply
-
Are you looking for ofxtools.utils.indent() ? Line 101 in 655549a |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for your interest. I'm trying to write a function that does a tree walk. I pass in an element of an OFX tree, and the function walks the entire subtree, recursively visiting each sub-element. The code I've prototyped is fragile and dependent on private implementation details. I'd much prefer to stick to interfaces that are more public. Looking through the ofxtools source, I find code that looks suggestive, but I typically run into trouble using it to discover the exact set of child nodes. It's the dynamic nature of ET.Elements that confuses me. (I think my brain is addled by metaprogramming.) Is there a function that returns the children of a given node? Something like |
Beta Was this translation helpful? Give feedback.
-
What's the best way to pretty-print an OFX tree?
I'm trying to pretty-print the result from parser.convert() for debug purposes. I want to walk the tree, printing each node in a human-readable format.
I've combed through various projects using ofxtools, but haven't been able to find code that does this.
I'm having moderate success using the pprint module. It's possible, but I'm using quite a bit of monkey-patching that depends on private implementation details.
Looking at the
__repr__()
implementation in https://github.com/csingley/ofxtools/blob/master/ofxtools/models/base.py suggests that there should be some elegant solution for walking an OFX tree and dumping the nodes. But I can't quite get my head around the best way to do that.Any suggestions? The output just needs to be human-readable. It doesn't need to be in a format that can be fed into any other program.
Beta Was this translation helpful? Give feedback.
All reactions