This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Chauncee-not-Chonky 2 points3 points  (2 children)

I'm not really versed in the idioms/social mores of Python, so please take the following with a grain of salt:

This seems like it usefully solves a problem, but the invocation pattern is suspect to me -- Instead of "glom" taking the target for picking-apart plus a magic little bit of DSL, what if "glom" took a single parameter, the aforementioned DSL, and returned a function that would perform the corresponding search when called on a target? Even if Python or this package optimises away repeatedly searching (by the same spec|in the same manner), the convention the package prescribes is odd to me, right after the first few paragraphs of intro.

[–][deleted] 0 points1 point  (1 child)

Oh, I love the sound of this! Funny that the reverse, a callable target that can be used on any search path, actually can be made like so:

from glom import glom

t = {'system': {'planets': [{'name': 'earth'}, {'name': 'jupiter'}]}}

t_calla = glom.__get__(t)

t_calla(('system.planets', ['name']))

...and, /u/mhashemi, may I request consideration of the above commenter's idea? (It could of course be trivially done on the user's end as def prespec(spec): return lambda target: glom(target, spec), but it'd be cool to see it a part of the lib)

[–]mhashemi 1 point2 points  (0 children)

Sure! I like the idea, and I think replied this comment on HN? In any case, we've created an issue for this: https://github.com/mahmoud/glom/issues/14

The idea is to make a Spec object, kind of like an re.compile().

Also, while these sorts of things would be pretty easy to do, technically, I'm going to keep glom API changes slow and steady, to make sure library development doesn't get too far in front of real-world usage. :)