Comment by giancarlostoro
3 days ago
Lowkey I hate the "\" line continuation in Python to force PEP-8 compliance in a way... Is there any Pythonistas who would write the examples in there differently to achieve a similar level of readability?
> pipeline = task(get_data, branch=True) \
> | task(step1, workers=20) \
> | task(step2, workers=20) \
> | task(step3, workers=20, multiprocess=True)
I really don’t like overloading pipes like this. I would rather chain methods like how the django orm does it.
you could reassign every line, but it would look nicer with chained functions.
edit:
I would be tempted to do something like this:
According to the docs, | is syntactic sugar for the .pipe method.
That's probably the chained method approach for those with this preference.
This style looks pretty good to me:
So does this style:
But it appears you can just change "task" to "Task" and then:
Wrap the statement in (...) and you can drop the backslashes. See also how people split up complicated loc queries in pandas on multiple lines too.
Thank you! It seems this works for not just parens but square brackets and curly braces too! Only special requirement is indentation is consistent (duh though).
I've not been doing Python day-to-day so I'm starting to lose my touch on all the nice little tricks.
Yeah, this seems neatest if you don't like line breaks
pipeline = (
)
Square brackets would create a list and braces would create a set of course. The contents still can be split over different lines-- just pointing that this syntax doesn't do the same thing.
2 replies →