[portland] PEP 8 Line Length Compliance

Robert Lugg Robert.Lugg at synopsys.com
Thu May 21 17:51:38 CEST 2015


I prefer Luciano's suggestions.  That said, another way is to build up the string from a list and then join the list elements.  For your case this is overkill:

l_res = list()
l_res.append('a bb ccc dddd eeeee ')
l_res.append('ffffff ggggggg hhhhhhhh')
res = ''.join(l_res)

Robert

-----Original Message-----
From: Portland [mailto:portland-bounces+robert.lugg=synopsys.com at python.org] On Behalf Of Luciano Ramalho
Sent: Thursday, May 21, 2015 8:42 AM
To: Python Users Group -- Portland, Oregon USA
Subject: Re: [portland] PEP 8 Line Length Compliance

On Thu, May 21, 2015 at 12:24 PM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
> On Thu, 21 May 2015, Luciano Ramalho wrote:
>> - Two or more string literals with no intervening tokens except 
>> whitespace are parsed as a single string literal.
>
>
>   Unless the string is delineated with single quotes (as in a content 
> list for a drop-down picklist control). :-)

The syntax I described works for any of the valid string delimiters in
Python: single quotes, double quotes, triple single quotes and triple double quotes, and the adjacent string literals do not need to use the same delimiter, you can mix and match and they'll still be parsed as one big string literal.

>   I'm used to seeing (and writing) newlines in bash scripts and other 
> text so now I know python recognizes it I can use this solution.

The problem with the trailing "\" is if someone accidentally types a space after it, the newline is no longer escaped, and most editors don't highlight this error, so you get a confusing message from the interpreter.

Best,

Luciano


>
> Much appreciated,
>
>
> Rich
> _______________________________________________
> Portland mailing list
> Portland at python.org
> https://mail.python.org/mailman/listinfo/portland



--
Luciano Ramalho
|  Author of Fluent Python (O'Reilly, 2015)
|     http://shop.oreilly.com/product/0636920032519.do
|  Professor em: http://python.pro.br
|  Twitter: @ramalhoorg
_______________________________________________
Portland mailing list
Portland at python.org
https://mail.python.org/mailman/listinfo/portland


More information about the Portland mailing list