[Tutor] import confusion

Kent Johnson kent37 at tds.net
Mon Jan 26 12:42:20 CET 2009


On Mon, Jan 26, 2009 at 12:31 AM, Marc Tompkins <marc.tompkins at gmail.com> wrote:

> Someone will no doubt phrase this better, but let's take a shot...
>

> 2)  "import django" makes the entire django package and all sub-modules
> available.  You could then refer to django.forms.DecimalField and
> django.contrib.auth.ImproperlyConfigured (for example) in your program, no
> further imports needed.

No; in general,
  import x
does not make module x.y available for use, you have to explicitly
  import x.y

In [1]: import django

In [2]: django.forms
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Users/kent/<ipython console> in <module>()
AttributeError: 'module' object has no attribute 'forms'

There are some exceptions that confuse the issue, for example you can
import os and then use os.path.whatever.

Other than that you are correct.

Kent


More information about the Tutor mailing list