[Python-ideas] Parenthesized Compound With Statement
Guido van Rossum
guido at python.org
Wed Jul 3 19:22:51 CEST 2013
Looks good, but I would add a mention of assert (without example) as
another case where using a backslash may make sense.
On Wed, Jul 3, 2013 at 8:48 AM, Barry Warsaw <barry at python.org> wrote:
> On Jul 03, 2013, at 08:38 AM, Guido van Rossum wrote:
>
>>Clearly some people have interpreted this dogmatically as "never use
>>backslashes", so I think we should explicitly update the PEP with more
>>moderate language and an example.
>
> How about this:
>
> diff -r bd8e5c86fb27 pep-0008.txt
> --- a/pep-0008.txt Wed Jul 03 00:44:58 2013 +0200
> +++ b/pep-0008.txt Wed Jul 03 11:46:07 2013 -0400
> @@ -158,9 +158,19 @@
> line continuation inside parentheses, brackets and braces. Long lines
> can be broken over multiple lines by wrapping expressions in
> parentheses. These should be used in preference to using a backslash
> -for line continuation. Make sure to indent the continued line
> -appropriately. The preferred place to break around a binary operator
> -is *after* the operator, not before it. Some examples::
> +for line continuation.
> +
> +Backslashes may still be appropriate at times. For example, long,
> +multiple ``with``-statements cannot use implicit continuation, so
> +backslashes are acceptable::
> +
> + with open('/path/to/some/file/you/want/to/read') as file_1, \
> + open('/path/to/some/file/being/written', 'w') as file_2:
> + file_2.write(file_1.read())
> +
> +Make sure to indent the continued line appropriately. The preferred
> +place to break around a binary operator is *after* the operator, not
> +before it. Some examples::
>
> class Rectangle(Blob):
>
--
--Guido van Rossum (python.org/~guido)
More information about the Python-ideas
mailing list