Python and PEP8 - Recommendations on breaking up long lines?

MRAB python at mrabarnett.plus.com
Thu Nov 28 13:43:46 CET 2013


On 28/11/2013 03:06, Ben Finney wrote:
> Ned Batchelder <ned at nedbatchelder.com> writes:
>
>> The important thing in a with statement is that the assigned name will
>> be closed (or otherwise exited) automatically.  The open call is just
>> the expression used to assign the name.  The expression there isn't
>> really important.  This looks odd, but works the same as what you
>> have:
>>
>>     input = open(self.full_path)
>>     output = open(self.output_csv, 'ab')
>>     with input as input, output as output:
>>         ...
>
> Excellent! That solves for me a significant irritation of the syntax for
> multiple context managers. Thank you.
>
What if the second 'open' raises an exception?




More information about the Python-list mailing list