[Tutor] Still Trying to Understand GAE

admin at gg-lab.net admin at gg-lab.net
Tue Sep 15 14:21:14 CEST 2009


Hi Wesley!

Thankyou very much for your mail (and i'd like to thankyou in a
special way for your corrections :) ).

> it imports all sub*packages*. don't think directories because the
> import mechanism doesn't work this way. this is likely because there
> are __init__.py files in those subdirectories. another possibility is
> that there are non-empty __init__.py files that do the imports of
> things that you're not expecting.

Ok, i've checked all those files, because in a standard python
evinronment the __init__.py is the only file that can decide what to
import.

If you want to check directly, here you can find the SDK. Just open
the "google" directory.

http://googleappengine.googlecode.com/files/google_appengine_1.2.5.zip

As i've said, this simple script:

---
#!/usr/bin/python
import google

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

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

print "google",dir(google)
print "</br>"
print "</br>"

print "</body>"
---

Gives this output:

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

The "google" directoy has an empty __init__.py file (well, if we want
to be completely correct it contains some commented -#- lines). Same
for "appengine", "net" and "pyglib". As they all have an __init__.py
file, they should be consiedered as modules from the python
interpreter. So, if i run "import google" it imports all google's
submodules.

Well, now, the problem: if i create another directory (module) in the
google dir, it doesn't get imported. Of course i've put in it some .py
files and an empty __init__.py file.


Thankyou again!
Giorgio

2009/9/13 wesley chun <wescpy at gmail.com>:
> hi Giorgio,
>
> welcome to Python (whether directly or from GAE!) :-) my comments below.
>
>
>> with import i can import modules or single functions. And this is ok.
>
> not quite true. regardless of whether you use import or from-import,
> you're *always* importing (and loading) modules or packages in their
> entirety.
>
> now, whether you have *access* to "entire" modules/packages or
> individual attributes (functions, classes, or standard data), is
> another matter -- usually this is a result of using from-import.
>
> also, the difference between importing and loading is that loading
> only happens the first time you import a module/package. (if you do it
> more than once, e.g., module A imports B and C and module B also
> imports C, the import of C happens twice but the loading happens only
> once.
>
>
>> if i use "import
>> google" it also imports all subdirectories. And i can't understand
>> wiìhy it does so.
>
> it imports all sub*packages*. don't think directories because the
> import mechanism doesn't work this way. this is likely because there
> are __init__.py files in those subdirectories. another possibility is
> that there are non-empty __init__.py files that do the imports of
> things that you're not expecting.
>
> hope this helps!
> -- wesley
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "Core Python Programming", Prentice Hall, (c)2007,2001
> "Python Fundamentals", Prentice Hall, (c)2009
>    http://corepython.com
>
> wesley.j.chun :: wescpy-at-gmail.com
> python training and technical consulting
> cyberweb.consulting : silicon valley, ca
> http://cyberwebconsulting.com
>


More information about the Tutor mailing list