[Tutor] Fwd: Import Modules

Kent Johnson kent37 at tds.net
Thu Apr 16 20:00:55 CEST 2009


Forwarding to the list


---------- Forwarded message ----------
From: GG Labs 10 <gg.labs10 at gmail.com>
Date: Thu, Apr 16, 2009 at 10:28 AM
Subject: Re: [Tutor] Import Modules
To: Kent Johnson <kent37 at tds.net>


Thankyou,

i think i've understood the problem.

Now, another App Engine related question:

This code:

---
import google

print "Content-Type: text/html"
print ""

print "<head>"
print "</head>"
print "<body>"

print "google",dir(google)

print "</body>"
---

Gives this output:

---
google ['__builtins__', '__doc__', '__file__', '__name__', '__path__',
'appengine', 'net', 'pyglib']
---

appengine, net and pyglib are path (so subpackages of google package),
not modules.

Why when i import the google package all those subpackages are
imported? In the __init__.py file i can't find anything (__all__ for
example), and if i add a directory with a .py file at the same level
of appengine, it doesn't get imported.

Thankyou


2009/4/16 Kent Johnson <kent37 at tds.net>
>
> On Thu, Apr 16, 2009 at 3:21 AM, ALAN GAULD <alan.gauld at btinternet.com> wrote:
> >
> >
> >> In general, importing a package does not give access to members of a
> >> sub-package.
> >
> > Interestingly I added the comment about sub packages specifically
> > because I remembered os.path and assumed it was the norm! :-)
>
> Yes, it took me a long time to realize that it is not. Strictly
> speaking I don't think os is even a package, it is a module that
> imports another module as it's path attribute. There is no os
> directory or os/__init__.py or os/path.py.
>
> Kent
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list