Re: [Tutor] Still Trying to Understand GAE

2009-09-17 Thread ad...@gg-lab.net
Thankyou all, you're very precious for me.

yeah it seems the development webserver (and the production one) are
importing modules in a non-standard way.

I absolutely don't understand this choice. Why import everything
everytime? Don't you think it makes scripts much more slow?

Giorgio

2009/9/16 Kent Johnson ken...@tds.net:
 On Sun, Sep 13, 2009 at 9:59 AM, ad...@gg-lab.net ad...@gg-lab.net wrote:
 Hi All,

 i've started earning python sone months ago (on Google App Engine
 unfortunately).

 I have some doubts reagrding import, and have asked a similar
 question here months ago, but without finding a solution.

 So:

 with import i can import modules or single functions. And this is ok.
 Then: as i have understood from all the books i readm in each package
 directory i have the __init__.py file that decides what import with
 it. In other words if my package skel is like:

 /gg/
 /gg/sub1/
 /gg/sub1/file.py
 /gg/sub2/
 /gg/sub2/file.py

 and i use import gg, nothing is imported. To import sub1 and sub2, i can:

 - Put in /gg/ a __init__.py file that tells to import them
 - Use from gg import sub1

 Ok now the $1 Billion question: google app engine has the same schema
 than my gg package, an empty __init__.py file, but if i use import
 google it also imports all subdirectories. And i can't understand
 wiìhy it does so.

 In general,
  import foo
 does not import subpackages of foo unless they are specifically
 imported in foo/__init__.py, so dir(foo) will not show the
 subpackages.

 However if you
  import foo
  import foo.bar
 then dir(foo) will include 'bar'. Here is an example from the std lib:

 In [1]: import distutils

 In [2]: dir(distutils)
 Out[2]:
 ['__builtins__',
  '__doc__',
  '__file__',
  '__name__',
  '__package__',
  '__path__',
  '__revision__',
  '__version__']

 In [3]: import distutils.cmd

 In [4]: dir(distutils)
 Out[4]:
 ['__builtins__',
  '__doc__',
  '__file__',
  '__name__',
  '__package__',
  '__path__',
  '__revision__',
  '__version__',
  'archive_util',
  'cmd',
  'dep_util',
  'dir_util',
  'errors',
  'file_util',
  'log',
  'spawn',
  'util']

 My guess is that the startup for GAE is importing the subpackages so
 they then appear as imported modules. To access your sub-package, just
 import it normally.

 Kent

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Still Trying to Understand GAE

2009-09-17 Thread Kent Johnson
On Thu, Sep 17, 2009 at 8:38 AM, ad...@gg-lab.net ad...@gg-lab.net wrote:
 Thankyou all, you're very precious for me.

 yeah it seems the development webserver (and the production one) are
 importing modules in a non-standard way.

 I absolutely don't understand this choice. Why import everything
 everytime? Don't you think it makes scripts much more slow?

My guess is that they are importing what they need. It does impact
startup but hey, if you need it, you need it.

Try this for comparison: Start Python from a command line, then
In [5]: import sys

In [6]: len(sys.modules)
Out[6]: 323

I have IPython loaded so this number may be larger than yours. In
Python 3, with no IPython, I get
 import sys
 len(sys.modules)
47

So my advice is, don't worry about it.

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Still Trying to Understand GAE

2009-09-17 Thread ad...@gg-lab.net
Yes Kent, i'm not worrying about it, i was just trying to find the
reason why they're doing so.

Anyway, i'm a newbye, but the GAE Evinronment is very very difficult
to understand. The only thing is thas in common with the real python
is the sintax.

Thankyou again

2009/9/17 Kent Johnson ken...@tds.net:
 On Thu, Sep 17, 2009 at 8:38 AM, ad...@gg-lab.net ad...@gg-lab.net wrote:
 Thankyou all, you're very precious for me.

 yeah it seems the development webserver (and the production one) are
 importing modules in a non-standard way.

 I absolutely don't understand this choice. Why import everything
 everytime? Don't you think it makes scripts much more slow?

 My guess is that they are importing what they need. It does impact
 startup but hey, if you need it, you need it.

 Try this for comparison: Start Python from a command line, then
 In [5]: import sys

 In [6]: len(sys.modules)
 Out[6]: 323

 I have IPython loaded so this number may be larger than yours. In
 Python 3, with no IPython, I get
 import sys
 len(sys.modules)
 47

 So my advice is, don't worry about it.

 Kent

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Still Trying to Understand GAE

2009-09-16 Thread Gerard Flanagan

ad...@gg-lab.net wrote:

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.




I would guess that additions have been made to the list of modules in 
sys.path. Where the code that is making these additions is located is 
another matter. Often, people manipulate sys.path from within 
__init__.py files but, as you have seen, this isn't the case for the 
google package - all the __init__.py are empty. To verify, navigate to 
the GAE directory, the one containing the 'google' package, and start a 
python interactive session. Then do


--- import google
--- dir(google)

You don't get 'appengine', 'net' etc. in the output.

So the google package *is* the same as your own package. The confusion 
is probably coming from the fact that you are doing your imports from 
'within' an already running process - the appserver, and this process 
has had a chance to manipulate sys.path before your code runs. Look at 
dev_appserver.py in the sdk and google/appengine/tools/dev_appserver.py 
- don't ask me what that code is doing, but perhaps there is a clue 
there, let us know if you find it!


Regards

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Still Trying to Understand GAE

2009-09-16 Thread Kent Johnson
On Sun, Sep 13, 2009 at 9:59 AM, ad...@gg-lab.net ad...@gg-lab.net wrote:
 Hi All,

 i've started earning python sone months ago (on Google App Engine
 unfortunately).

 I have some doubts reagrding import, and have asked a similar
 question here months ago, but without finding a solution.

 So:

 with import i can import modules or single functions. And this is ok.
 Then: as i have understood from all the books i readm in each package
 directory i have the __init__.py file that decides what import with
 it. In other words if my package skel is like:

 /gg/
 /gg/sub1/
 /gg/sub1/file.py
 /gg/sub2/
 /gg/sub2/file.py

 and i use import gg, nothing is imported. To import sub1 and sub2, i can:

 - Put in /gg/ a __init__.py file that tells to import them
 - Use from gg import sub1

 Ok now the $1 Billion question: google app engine has the same schema
 than my gg package, an empty __init__.py file, but if i use import
 google it also imports all subdirectories. And i can't understand
 wiìhy it does so.

In general,
  import foo
does not import subpackages of foo unless they are specifically
imported in foo/__init__.py, so dir(foo) will not show the
subpackages.

However if you
  import foo
  import foo.bar
then dir(foo) will include 'bar'. Here is an example from the std lib:

In [1]: import distutils

In [2]: dir(distutils)
Out[2]:
['__builtins__',
 '__doc__',
 '__file__',
 '__name__',
 '__package__',
 '__path__',
 '__revision__',
 '__version__']

In [3]: import distutils.cmd

In [4]: dir(distutils)
Out[4]:
['__builtins__',
 '__doc__',
 '__file__',
 '__name__',
 '__package__',
 '__path__',
 '__revision__',
 '__version__',
 'archive_util',
 'cmd',
 'dep_util',
 'dir_util',
 'errors',
 'file_util',
 'log',
 'spawn',
 'util']

My guess is that the startup for GAE is importing the subpackages so
they then appear as imported modules. To access your sub-package, just
import it normally.

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Still Trying to Understand GAE

2009-09-15 Thread ad...@gg-lab.net
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 wes...@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

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Still Trying to Understand GAE

2009-09-13 Thread ad...@gg-lab.net
Hi All,

i've started earning python sone months ago (on Google App Engine
unfortunately).

I have some doubts reagrding import, and have asked a similar
question here months ago, but without finding a solution.

So:

with import i can import modules or single functions. And this is ok.
Then: as i have understood from all the books i readm in each package
directory i have the __init__.py file that decides what import with
it. In other words if my package skel is like:

/gg/
/gg/sub1/
/gg/sub1/file.py
/gg/sub2/
/gg/sub2/file.py

and i use import gg, nothing is imported. To import sub1 and sub2, i can:

- Put in /gg/ a __init__.py file that tells to import them
- Use from gg import sub1

Ok now the $1 Billion question: google app engine has the same schema
than my gg package, an empty __init__.py file, but if i use import
google it also imports all subdirectories. And i can't understand
wiìhy it does so.

Can you help me?

Thankyou

Giorgio
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Still Trying to Understand GAE

2009-09-13 Thread wesley chun
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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor