Which of the best choice ?

Alex Martelli aleax at aleax.it
Wed Nov 12 11:55:36 CET 2003

SungSoo, Han wrote:

> There are two coding style when python import module.
>  (1) import sys
>  (2) from import sys (or from import *)
> I prefer (1) style. Because it's easy to read, understand module in any
> category .
> Which prefer ?

Style (1) is generally to be preferred.  "from X import *" is almost
universally shunned because it fills your namespace in ways that you
can't really control.  There may be a few good nice ways to use 'from'
(one is getting a single module from a package), but in general if you
were to forget the existence of the 'from' statement, in favour of
using only the 'import' statement, your Python code wouldn't suffer.


More information about the Python-list mailing list