May-01-2017, 02:01 PM
Yeah, that gives the same results, but it was just a toy class to demonstrate where it could syntactically be useful.
What if each filter was unrelated from the others? Like, what if it's a wrapper around BeautifulSoup, and each query is a sub-selector of the parent filter's result?
The original example could also be written like this, though I think using backslashes looks worse than the dangling parentheses...
What if each filter was unrelated from the others? Like, what if it's a wrapper around BeautifulSoup, and each query is a sub-selector of the parent filter's result?
The original example could also be written like this, though I think using backslashes looks worse than the dangling parentheses...
things = query(range(1000)) \ .where(lambda x: x % 2 == 0) \ .where(lambda x: x % 3 == 0) \ .where(lambda x: x % 4 == 0) \ .where(lambda x: x % 5 == 0)