How would I go about breaking the following line? The PEP8 guideline doesn't make it very clear to me.
confirmation_message = _('ORDER_CREATED: %(PROPERTY_1)s - %(PROPERTY_2)s - %(PROPERTY_3)s - %(PROPERTY_4)s') % {'PROPERTY_1': order.lorem, 'PROPERTY_2': order.ipsum, 'PROPERTY_4': order.dolor, 'PROPERTY_5': order.sit}
1.9 Breaking long linesWith the option -l n , or --line-length n , it is possible to specify the maximum length of a line of C code, not including possible comments that follow it. When lines become longer than the specified line length, GNU indent tries to break the line at a logical place.
In Python, the new line character “\n” is used to create a new line. When inserted in a string all the characters after the character are added to a new line. Essentially the occurrence of the “\n” indicates that the line ends here and the remaining characters would be displayed in a new line.
One would typically do something like:
confirmation_message = _(
'ORDER_CREATED: %(PROPERTY_1)s - '
'%(PROPERTY_2)s - %(PROPERTY_3)s - %(PROPERTY_4)s') % {
'PROPERTY_1': order.lorem,
'PROPERTY_2': order.ipsum,
'PROPERTY_3': order.ipsum,
'PROPERTY_4': order.dolor,
'PROPERTY_5': order.sit
}
This takes advantage of the fact that adjacent strings ('like ' 'this'
) are concatenated to shorten the long line of text; everything else is split on commas.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With