
On 07/10/2019 14:52, Random832 wrote:
On Mon, Oct 7, 2019, at 09:22, Rhodri James wrote:
On 04/10/2019 20:34, Caleb Donovick wrote:
The first and perhaps the most obvious, is doing relational queries. ``` where_x_1 = db[x=1] ``` is more beautiful than ``` where_x_1 = db[dict(x=1)] where_x_1 = db[{'x': 1}] # or by abusing slices where_x_1 = db['x':1] # or in the style of Pandas where_x_1 = db[db['x'] == 1] ```
OK, I'm not sure what you're trying to do here, which all on its own says that what you're doing isn't self-explanatory. Would I be right in thinking you want a shorthand for:
where_x_1 = [k for k,v in db if v == 1]
If so, I'd rather the comprehension, thanks. It at least says what it does.
It'd be [v for v in db if v['x'] == 1], anyway,
Sorry. I regard this as more proof that what's being asked for isn't in the least bit obvious!
but the point is the list comprehension can't be analyzed by frameworks like Pandas (to execute more efficiently) or SqlAlchemy (to turn it into a sql query that gets executed server-side). And for that matter can't return any type other than a list [or generator, if you used the generator expression syntax instead]
Or a dict, or a set... or whatever the right tool for the specific job actually turns out to be. I still think it's completely wrong-headed syntax trying to do something that would be much better done another way, in particular explicitly. Caleb is right that "db[x=1]" looks prettier than all his alternatives, but that's a really low bar. Is there something inherently wrong with a functional interface? -- Rhodri James *-* Kynesim Ltd