Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you do method chaining?
#4
(May-01-2017, 02:01 PM)nilamo Wrote: 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)
Actually - while I hate backlashes - I would rather use this option - it's ugly but it's more obvious
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
How do you do method chaining? - by nilamo - May-01-2017, 02:36 AM
RE: How do you do method chaining? - by Mekire - May-01-2017, 06:36 AM
RE: How do you do method chaining? - by nilamo - May-01-2017, 02:01 PM
RE: How do you do method chaining? - by volcano63 - May-01-2017, 04:06 PM
RE: How do you do method chaining? - by nilamo - May-01-2017, 04:34 PM
RE: How do you do method chaining? - by Mekire - May-01-2017, 10:19 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020