You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use the recursive wildcard feature on a nested dictionary. Some of the objects in the dictionary have attributes which are iterators. However, after the glom search the iterators produce a StopIteration exception on the next call to next. I have produced a minimal example below:
Is this the excepted behaviour? If so, is it possible to limit how far the recursion goes? I would like to be able to limit it to only look inside the nested dictionary and not the objects contained within.
Many thanks,
Lewis
The text was updated successfully, but these errors were encountered:
That is kind of expected behavior. ** is going to keep going as deep as it can.
If know the depth that you want to go, a *.*.* type path can work to not go too far.
Switch, Match and Flatten could be combined to put a little bit of logic around which types of things to iterate on.
Ref('unpack',
Match(
Switch({
dict: Auto('*'), # only go 1 level on dictsobject: Auto(('*', Flatten([Ref('unpack'])) # for everything else, recurse and combine results into one iterable
}))
)
But, honestly, I think you are better off using a custom self-recursive function if you need to get really fine-grained about when you do and don't want to iterate.
Hello,
I am trying to use the recursive wildcard feature on a nested dictionary. Some of the objects in the dictionary have attributes which are iterators. However, after the glom search the iterators produce a
StopIteration
exception on the next call tonext
. I have produced a minimal example below:Which produces:
Is this the excepted behaviour? If so, is it possible to limit how far the recursion goes? I would like to be able to limit it to only look inside the nested dictionary and not the objects contained within.
Many thanks,
Lewis
The text was updated successfully, but these errors were encountered: