Python and PEP8 - Recommendations on breaking up long lines?

Steven D'Aprano steve at pearwood.info
Wed Nov 27 22:58:53 EST 2013


On Wed, 27 Nov 2013 21:59:56 -0500, 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.)


That's really clever! Why didn't I think of that?


-- 
Steven



More information about the Python-list mailing list