TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Glom – Restructured Data for Python

313 点作者 mhashemi大约 7 年前

26 条评论

nerdponx大约 7 年前
It&#x27;s a nice idea, but i never like writing what amounts to a DSL in strings in my code (yes, that applies to in-code SQL as well, although that&#x27;s often unavoidable).<p>I prefer the `get_in()` method from Toolz: <a href="http:&#x2F;&#x2F;toolz.readthedocs.io&#x2F;en&#x2F;latest&#x2F;api.html#toolz.dicttoolz.get_in" rel="nofollow">http:&#x2F;&#x2F;toolz.readthedocs.io&#x2F;en&#x2F;latest&#x2F;api.html#toolz.dicttoo...</a>
评论 #17035097 未加载
评论 #17033701 未加载
评论 #17033834 未加载
评论 #17033631 未加载
评论 #17034195 未加载
hessammehr大约 7 年前
This might have been unintentional, but I suspect &quot;Spectre of Structure&quot; and &quot;Python&#x27;s missing piece&quot; refer to Nathan Marz&#x27;s specter library for clojure [1], similarly touted as clojure&#x27;s missing piece. I tend to agree in the case of specter, given the mind-boggling types of transformations that are easily (and simply) expressed in it (and often run faster than idiomatic clojure as well). Highly recommended if you ever need to work with deeply nested data structures.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;nathanmarz&#x2F;specter" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;nathanmarz&#x2F;specter</a>
评论 #17032719 未加载
faitswulff大约 7 年前
This is really cool. Did you ever consider an API to do the reverse - to insert a value at a particular point in the data?<p>My interest stems from this issue[0] on the Ruby issue tracker to make a symmetrical method to Hash#dig (which does something similar to, but more limited than glom) called Hash#bury. The problem in the issue was that inserting a value at a given index in an array proved difficult and unnatural in Ruby, so I was wondering if there were other solutions out there.<p>Another question occurs to me - does glom only support string keys?<p>[0]: <a href="https:&#x2F;&#x2F;bugs.ruby-lang.org&#x2F;issues&#x2F;11747" rel="nofollow">https:&#x2F;&#x2F;bugs.ruby-lang.org&#x2F;issues&#x2F;11747</a>
评论 #17032575 未加载
评论 #17058123 未加载
评论 #17032587 未加载
jbritton大约 7 年前
There is also this Python lens library. <a href="https:&#x2F;&#x2F;github.com&#x2F;ingolemo&#x2F;python-lenses" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ingolemo&#x2F;python-lenses</a><p>I can&#x27;t say how they compare, but they have some overlapping features.
derefr大约 7 年前
My favourite approach to this so far, that I would like other libraries to copy, is Elixir’s Access protocol, which gives you e.g.:<p><pre><code> foo = %{key: [[1, 2], [3, 4], [5, 6]]} path = [:key, Access.all, Access.at(0)] get_in foo, path # =&gt; [1, 3, 5] update_in foo, path, &amp;(&amp;1 * 10) # =&gt; %{key: [[10, 2], [30, 4], [50, 6]]} foo |&gt; put_in([:key, Access.all], “foo”) |&gt; put_in([:new_key], “bar”) # =&gt; %{key: [“foo”, “foo”, “foo”], new_key: “bar”} </code></pre> That third form is essentially the equivalent of building up a complex object through a series of mutations—but entirely functional.
tathougies大约 7 年前
This seems like lenses for python... neat! I often use python to mess around with things, and almost always miss Haskell&#x27;s lenses when doing so. This seems like an interesting solution.
amock大约 7 年前
I haven&#x27;t played with this yet, but it looks really handy. I deal with much more JSON on the command line than I&#x27;d like, so I think having both a single library and command line tool to reshape that data will make that much easier. I&#x27;ve used jq a few times, but when I want to move a little beyond what it does I usually end up writing a Python script. Hopefully this will make that transition smoother.
评论 #17032397 未加载
spedru大约 7 年前
I&#x27;m not really versed in the idioms&#x2F;social mores of Python, so please take the following with a grain of salt:<p>This seems like it usefully solves a problem, but the invocation pattern is suspect to me -- Instead of &quot;glom&quot; taking the target for picking-apart plus a magic little bit of DSL, what if &quot;glom&quot; 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.
评论 #17035330 未加载
评论 #17035382 未加载
agf大约 7 年前
It seems to me like the advantage to focus on here is the improved error &#x2F; `None` handling, which will speed debugging and make handling expected edge cases easier. I&#x27;ve seen a lot of inexperienced developers tripped up entirely by this kind of data access, and seen plenty of experienced developers waste time debugging it because of the exact error cases the announcement references.<p>The `T` object, which the article describes as its most powerful, can be a useful pattern in some situations, but it&#x27;s worth pointing out it isn&#x27;t new or unique to this project.<p>The author says in another thread here that he first started working on the &quot;stuff leading up to glom&quot; in 2013. One older example, which is virtually identical though less complete, is this Stack Overflow answer I posted in 2012: <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;9920723&#x2F;500584" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;9920723&#x2F;500584</a><p>I&#x27;d seen the general pattern even before that post, if not the Pythonic syntax. I don&#x27;t think that it&#x27;s much of an improvement over defining a `lambda`, so again I would say the thing to focus on is the improved debugability and the simpler, dot-notation-as-generic-attribute-or-item-accessor syntax. I think `T` is largely a distraction, or should be reserved for advanced users.
评论 #17038785 未加载
tincholio大约 7 年前
It looks quite similar in spirit to Clojure&#x27;s Specter library (<a href="https:&#x2F;&#x2F;github.com&#x2F;nathanmarz&#x2F;specter" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;nathanmarz&#x2F;specter</a>), and even seems to have a nod to it (The Spectre of Structure).
评论 #17032505 未加载
评论 #17032648 未加载
lapnitnelav大约 7 年前
Looks really neat.<p>Striking a balance between ease of use &#x2F; simplicity and powerful features is a tough exercise but you did well.<p>I can foresee the CLI being quite useful to do away with the run-of-the-mill sed &#x2F; awk &#x2F; grep [...] mess. Specifically for the less CLI inclined people out there.
wbolster大约 7 年前
in a similar spirit, i wrote &quot;sanest&quot;, sane nested objects, tailored specifically for json fornats: <a href="https:&#x2F;&#x2F;sanest.readthedocs.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;sanest.readthedocs.io&#x2F;</a><p>it does not have the exact same feature set though. my focus was mostly on both reading and modifying nested structures in a type safe way.
bluemanshoe2大约 7 年前
Compare&#x2F;contrast with pstar: <a href="https:&#x2F;&#x2F;github.com&#x2F;iansf&#x2F;pstar" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;iansf&#x2F;pstar</a>
icebraining大约 7 年前
Can it be used bidirectionally, without having to repeat the work?<p>I have a need to transform between pairs of structures, in both directions, and ever since I found JsonGrammar (<a href="https:&#x2F;&#x2F;github.com&#x2F;MedeaMelana&#x2F;JsonGrammar2" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;MedeaMelana&#x2F;JsonGrammar2</a>) I&#x27;ve been pining for a Python version.
评论 #17032860 未加载
评论 #17033059 未加载
sixdimensional大约 7 年前
I had a quick look, but I didn&#x27;t see filtering expressions, only shaping expressions. It seems like glom is more of a result shaper&#x2F;mapper. Can you filter with glom (maybe with lambdas or something)? I could see the two going together quite well if you were &quot;glomming&quot; a big Python object.
评论 #17033789 未加载
pdobsan大约 7 年前
There is already a well established Gnome project with the same name: <a href="http:&#x2F;&#x2F;www.glom.org" rel="nofollow">http:&#x2F;&#x2F;www.glom.org</a> It is a GTK+ front-end to PostgreSQL, similar to Microsoft Access.
harel大约 7 年前
This reminds me a little of the excellent dpath lib: <a href="https:&#x2F;&#x2F;github.com&#x2F;akesterson&#x2F;dpath-python" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;akesterson&#x2F;dpath-python</a>
jasonpeacock大约 7 年前
I&#x27;m probably being dense, but I don&#x27;t see a good description of the input data types supported - the CLI says &quot;json or python&quot;.<p>It would be great to have clarification if this is JSON only, or supports other data structures, or parsers could be plugged in?
评论 #17033191 未加载
codezero大约 7 年前
This is pretty neat and is something I&#x27;ve been thinking about for a current project.<p>Does anyone know if something similar exists in Java&#x2F;Scala land?
评论 #17037930 未加载
staticautomatic大约 7 年前
Aside: are there any libraries for JSON or dict-like formats with xpath-style querying that are as quick under the hood as lxml is for xml?
heavenlyblue大约 7 年前
I think this project defines the first step at transitioning pip to a js-like repository of single-function modules. Hurray for kool-aid.
loop0大约 7 年前
I&#x27;m curious about how the author replaced DRF with glom
评论 #17035788 未加载
wildleaf大约 7 年前
Shameless plug: <a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;safely-nested" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;safely-nested</a><p>Nothing special, glom just reminded me of it.
boringg大约 7 年前
Looks slick!
zestyping大约 7 年前
The writing style is just insufferable. Even the API documentation is littered with hyperbole and self-congratulation. We get it, you&#x27;re proud of your work and <i>extremely</i> proud of yourself.<p>&gt; &quot;as simple and powerful as glom&quot;<p>&gt; &quot;big things come in small packages&quot;<p>&gt; &quot;small API with big functionality&quot;<p>&gt; &quot;power is only surpassed by its intuitiveness&quot;<p>&gt; &quot;simplicity is only surpassed by its utility&quot;<p>&gt; &quot;shortest-named feature may be its most powerful&quot;<p>For heaven&#x27;s sake, give it a rest!<p>It&#x27;s a big red flag about your priorities that when I go looking for a precise specification, I can&#x27;t find answers to simple questions and instead end up wading through incessant marketing phrases. I tried, and I finally gave up halfway through the API doc. It might even be the case that glom is a good idea—but you&#x27;re making it really hard to trust you as a source of objective information about it.<p>Show, don&#x27;t tell. My advice to you: you&#x27;ll generate more interest if you delete every congratulatory word on those pages and focus entirely on helping your readers understand what glom does instead of trying to sell it to them.
评论 #17034626 未加载
评论 #17035874 未加载
评论 #17035806 未加载
rodrigoalviani大约 7 年前
Cool... it looks like... errr... javascript :D