[Tutor] Import Modules

Alan Gauld alan.gauld at btinternet.com
Thu Apr 16 00:57:41 CEST 2009

"Giorgio Bonfiglio" <gg.labs10 at gmail.com> wrote

> from google.appengine.ext import webapp
> from google.appengine.ext.webapp.util import run_wsgi_app
> The first line imports the webapp subpackage (that is not actually a 
> module,
> it's a subdirectory with some .py files into). So why do i need to import
> the specific function in the second line? Does'nt it get imported in the
> first?

The webapp name will get imported but to reach the function you
would need to use


Somebody decided that was too close to hard work so they imported
that specific function.

When you import you import names, in the first case webapp.
Where the name is a package (ie a folder) that gives you access
to the modules (or sub packages) contained in that folder but
not to the contents of those items directly, hence the need for

You could just use the long name each time but the direct
import makes for shorter coding, especially if you use the
function a lot.


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list