Namespace question

Fredrik Lundh fredrik at pythonware.com
Tue Apr 3 10:04:17 EDT 2001


> I am a little confused on what import does in a module's
> namespace (Python 2.0).
>
> import random

imports the random module into its own namespaces, and adds a
"random" object to your namespace.

> from Numeric import *

imports *everything* that happens to be in the Numeric module
into your namespace, including things with the same name that
happens to be there already.

> The "matrixmultiply" method from NumPy can be used with
> no additional import statement, but the random.choice() method
> will throw an AttributeError exception without another "import
> random" statement. Why doesn't the first "import random" put
> it into the module namespace?

probably because there's something else called "random" in the
Numeric (or more likely, RandomArray) module.

also see:

    http://effbot.org/guides/import-confusion.htm

Cheers /F

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list