Menu
Menu
DaniWeb
Log In
Sign Up
Read
Contribute
Meet
Search
Search
About 10 results for
xmltodict
- Page 1
xmltodict - not understanding how to make it fully useful
Programming
Software Development
9 Years Ago
by flebber
… can grab single elements just fine. In [10]: %paste import
xmltodict
document = open("/home/sayth/Scripts/va_benefits/20140513HAWK0.xml"…;, "r") read_doc = document.read() xml_doc =
xmltodict
.parse(read_doc) ## -- End pasted text -- In [11]: xml_doc['meeting']['@id…
Re: xmltodict - not understanding how to make it fully useful
Programming
Software Development
9 Years Ago
by flebber
1 import
xmltodict
2 3 document = open("/home/sayth/Scripts/va_benefits/20140513HAWK0.…", "r") 4 read_doc = document.read() 5 xml_doc =
xmltodict
.parse(read_doc) 6 EE 7 @post_process(list) 8 def gather…
Re: xmltodict - not understanding how to make it fully useful
Programming
Software Development
9 Years Ago
by Gribouillis
You can define a function to do the same easily @post_process(list) def gather(xml_doc, paths): for p in paths: node = xml_doc for word in p: node = getitem(node, word) yield node a = gather(xml_doc, (('meeting', '@id'), ('meeting', '@venue'))) `post_process` is …
Re: xmltodict - not understanding how to make it fully useful
Programming
Software Development
9 Years Ago
by flebber
Wow, your a legend. How does this compare to using a Python function such as filter.
Re: xmltodict - not understanding how to make it fully useful
Programming
Software Development
9 Years Ago
by Gribouillis
> How does this compare to using a Python function such as filter. Can you be more specific ? The role of `filter()` is to select a subsequence in a sequence. It is a different problem.
Re: xmltodict - not understanding how to make it fully useful
Programming
Software Development
9 Years Ago
by flebber
No it is different I was trying to use filter after I posted this last night and saw your post use. a = gather(xml_doc, (('meeting', '@id'), ('meeting', '@venue'))) and thought if that was a function(which is what you created). Don't worry just because it was the last thing I did late lst night. def gather(a): a = gather…
Re: xmltodict - not understanding how to make it fully useful
Programming
Software Development
9 Years Ago
by Gribouillis
In this case, the decorator transform a function which generate values into a function which returns a list of these values. Without the decorator, I would write def gather(xml_doc, paths): result = [] for p in paths: node = xml_doc for word in p: node = getitem(node, word) …
Re: xmltodict - not understanding how to make it fully useful
Programming
Software Development
9 Years Ago
by Gribouillis
Sorry I meant @post_process(list) def gather(xml_doc, paths): for p in paths: node = xml_doc for word in p: node = node[word] yield node `getitem()` exists, but it is in module `operator`. You must also import `post_process()` from another file. For example, store it in a module …
Re: xmltodict - not understanding how to make it fully useful
Programming
Software Development
9 Years Ago
by flebber
Do I need to write anything in post_process.py?
Re: xmltodict - not understanding how to make it fully useful
Programming
Software Development
9 Years Ago
by Gribouillis
Of course, I said it is this code snippet: http://www.daniweb.com/software-development/python/code/374530/post-process-generated-values-with-a-decorator Here is the contents of post_process.py # python >= 2.6 from functools import update_wrapper def post_process(*filters): """Decorator to post process a …
Search
Search
Forum Categories
Hardware/Software
Programming
Digital Media
Community Center
Latest Content
Newest Topics
Latest Topics
Latest Posts
Latest Comments
Top Tags
Topics Feed
Social
Meet People
Forums
Top Members
Community Functions
DaniWeb Premium
Newsletter Archive
Markdown Syntax
Community Rules
Developer APIs
Connect API
Forum API Docs
Tools
SEO Backlink Checker
Legal
Terms of Service
Privacy Policy
FAQ
About Us
Advertise
Contact Us
© 2024 DaniWeb® LLC