-
Notifications
You must be signed in to change notification settings - Fork 64
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
How can I use glom to pick out zero, one, or more, array elements with a key that must match a value, and how to load this spec from file #225
Comments
Ah Wow.. As seen in the snippets, this seems to do the trick for the first part of the question: I simply replace the target, with my target, and the integer modulo check (inside the spec) with
I'm starting to love glom, and I only just met glom today! I think I am good for Part 1. Could you please help with a spec for Part 2, Part 3, and Part 4. |
Looks like Parts 2 and 3 are also easy. Something like this does the job.
So at this point I just need an answer for Part 4. |
That's a great question :-) You're knocking on the door of very universal computer science issues. Can we load an arbitrary spec WITHOUT eval? A spec can embed arbitrary python objects and functions so cannot be represented without "full power" python. My practical recommendation would be to have Could you have a LIMITED spec and load parts of it from JSON or similar? Yes, absolutely. I think it will end up being less readable than using a python-syntax config file, but it could be done. |
@davesargrad I also encountered this issue, did you find any solution, My problem is similar to Part 2 scenario. |
Part 1
My target looks like this:
I want to form a spec that will output just the element(s) of "a_list" that contain
"SOURCE TYPE": "Something Else"
So the output would be this:
Keep in mind this is also a valid target (Two matching "a_list" array elements, so the output would contain a list of length 2),
Is there a spec that can do this?
Part 2
Here, I want to preserve a portion of the higher level object as well
The target is the same, but I want the following output:
How would I achieve that?
Part 3
Here, I want to preserve a portion of the higher level object as well. I also want to leave out some fields, both in the higher level object, and in the matching array elements.
The target is the same, but I want the following output:
How would I achieve that?
Part 4
I dont want to configure the spec in a hard-coded fashion. Rather I want to load it as a configuration.
I could wrap the spec in a string and then do an eval. However I think this is bad practice.
As described in the documentation, I don't want to use code injection, nor do I want to use the command line interface for this. I'd rather load the spec from a configuration file, and still have access to the full power of the spec (so that I can use things like lambda functions, and methods such as Coalesce)
How do I load the glom spec from a configuration file, or from a string?
The text was updated successfully, but these errors were encountered: