[Tutor] Confused about "import Numeric" vs "import numpy" for Arrays

Kent Johnson kent37 at tds.net
Sat Aug 9 00:31:53 CEST 2008


On Fri, Aug 8, 2008 at 1:25 PM, Timothy Grant <timothy.grant at gmail.com> wrote:

> In general "from <module> import *" is a very bad idea.
>
> import <module> imports a module into its own namespace (e.g., to
> access its functionality you would have to do "<module>.foo() and
> <module>.bar()" The form that you chose to use imports all of a
> module's contents into the current namespace. This means you can call
> "foo()" and "bar()" directly, but it also means that if you have coded
> a "foo()" and a "bar()" you will not have access to the functions in
> the module you just imported.

Another reason not to use "from xx import *" is that it can make it
very difficult to discover where a name is defined. If you have
several "from xx import *" lines and then later you use a function
"foo()" there is no easy way to tell which module foo came from.

An alternative is to list just the names you want to import:
from xx import foo

Kent


More information about the Tutor mailing list