Backslash line continuation makes code less readable
my_very_big_string = “”””””For a long time I used to go to bed early. Sometimes, \
when I had put out my candle, my eyes would close so quickly that I had not even \
time to say “I’m going to sleep.”””””””
from some.deep.module.inside.a.module import a_nice_function, another_nice_function, \
my_very_big_string = (
“”For a long time I used to go to bed early. Sometimes, “”
“”when I had put out my candle, my eyes would close so quickly “”
“”that I had not even time to say “I’m going to sleep.”””
from some.deep.module.inside.a.module import (
a_nice_function, another_nice_function, yet_another_nice_function)
Why you should care
A better solution is to use parentheses around your elements. Left with an unclosed parenthesis on an end-of-line the Python interpreter will join the next line until the parentheses are closed. The same behavior holds for curly and square braces.
It is recommended to avoid these in order to ensure the code is more readable and cost effective.
About CAST and Highlight’s Code Insights
Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.