Python and PEP8 - Recommendations on breaking up long lines?

Ethan Furman ethan at stoneleaf.us
Wed Nov 27 22:15:15 EST 2013


On 11/27/2013 06:59 PM, Ned Batchelder wrote:
>
> 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:
>          ...
>
> (Use different names for the two parts of the "as" clauses if you like.)

Or skip the `as` clauses all together:

   input = ...
   output = ...
   with input, output:
     ...

works just fine.  (At least on 2.7 where I tested it. ;)

--
~Ethan~



More information about the Python-list mailing list