-
Notifications
You must be signed in to change notification settings - Fork 463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New User questions... #327
Comments
@martinblech I've created a function to walk over a list. The call simplifies things but I consider the function itself a hack. It's ~30 lines long. So I do something like:
So the real question now is... is there a better way? |
Please share a sample XML so we can reproduce your issue. |
It's just standard XML. I'm asking is there a better way to request a path into
the dictionary items.
Say I want this path /path1/path2/path3/someField
Python doesn't allow
path = /path1/path2/path3/someField
theDict[path]
or
path = /path1/path2/path3/
theDict.getLocation(path)
The desire here is to simply my code and either get the field or XML
block at those locations. If I know I'll be inside a block for a while
this can speed up my code and simplify usage as well as make the
code more readable.
In short... Is there another way to make the request. Does your package offer
up another method?
… On Jul 7, 2023, at 9:26 AM, Baptiste Fontaine ***@***.***> wrote:
Please share a sample XML so we can reproduce your issue.
|
(I’m just another user of If your XML contains only a single field of each tag, you could use As far as I know, xmltodict just parses the XML into a dict; it doesn’t offer any way to traverse that dict. There are other libraries that offer that kind of feature (lxml is probably the most popular) but if you already use xmltodict it might be overkill to change libraries just for that. If you search for "nested dict" on StackOverflow you might be able to find a suitable solution (see here for example). |
kk TY for the response. I like that page but I'm also looking for a response to that last example.
key = ("a", "b", "c")
The objective now is to create some function that works as follows:
>> getitem(d, key)
0
This format can also conveniently be applied directly as the __getitem__ method of a class.
One more constraint: I want the function to fail noisily when it is asked to get a non-existing key.
Not throwing an exception but returning standard errors like invalid key.
I'll keep looking TY.
… On Jul 7, 2023, at 1:36 PM, Baptiste Fontaine ***@***.***> wrote:
If you search for "nested dict" on StackOverflow you might be able to find a suitable solution
|
Love that you created this tool so TY up front. I'm having the following issues:
I know this is invalid... Just showing a concept here:
`basePath = ['FMSaveAsXML']
structPath = [basePath]['Structure']
layPath = structPath['LayoutCatalog'] # want an iterable pointer to this location
print ( 'Ver: ' + str(basePath['@Version']))
print ( 'layout: ' + str(layPath[0]['LayoutName']))
`
The text was updated successfully, but these errors were encountered: