Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51486 > unrolled thread

Re: import syntax

Started byTim Chase <python.list@tim.thechases.com>
First post2013-07-29 15:14 -0500
Last post2013-07-29 15:14 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: import syntax Tim Chase <python.list@tim.thechases.com> - 2013-07-29 15:14 -0500

#51486 — Re: import syntax

FromTim Chase <python.list@tim.thechases.com>
Date2013-07-29 15:14 -0500
SubjectRe: import syntax
Message-ID<mailman.5262.1375128799.3114.python-list@python.org>
On 2013-07-29 15:48, Devyn Collier Johnson wrote:
> The PEP8 recommends importing like this:
> 
> import os
> import re
> 
> not like this:
> 
> import os, re
> 
> Why is that? Is there a performance advantage to one of the styles?

While I don't believe there's much of a performance difference (if
so, it should be pretty negligible, especially since imports are
usually just done at load-time rather than run-time), but

1) it's easier to read one-per-line (IMHO), particularly if you sort
them alphabetically

2) it makes for cleaner diffs

Which would you rather read and try to figure out what's going on?

  =====================================
  --- before.py   2013-07-29 15:04:38.250996094 -0500
  +++ after.py    2013-07-29 15:04:44.026996132 -0500
  @@ -1 +1 @@
  -import csv, re, sys, os
  +import csv, re, sys, glob, os
  =====================================

vs.

  =====================================
  --- before.py   2013-07-29 15:13:13.050997907 -0500
  +++ after.py    2013-07-29 15:13:18.434997950 -0500
  @@ -1,4 +1,5 @@
   import csv
  +import glob
   import os
   import re
   import sys
  =====================================

The latter makes it much easier (at least for me) to spot that "glob"
was added.  And it's more tolerant of merge-conflict resolution.

-tkc



[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web