Dear Dabo,

        I been read python books and using the web to learn python.  I am using
Ubuntu 8.04 with dabo:

Platform: GTK
Python Version: 2.5.2 on linux2
Dabo Version: Version 0.9.0; Revision 4899
UI Version: 2.8.9.1 on wxGTK (gtk2)

        I use dabo dabo.quickStart("syseroMain") to create my working project
directory that contains main.py script module and five sub-directories
biz, db, reports, resources and ui.  In each sub-directory has a file
__init__.py that will contain a from import statements to relate each
module with its class.

        When reading about the __init__.py in Modules -- Python v2.6.1
documentation, it appears in the section Packages.  It state that
"Packages are a way of structuring Python's module namespace by using
"dotted module names. For example, the module name A.B designates a
submodule name B in a package name A." 

        Later in that article they show a hierarchical filesystem for a simple
example handling a sound system as:

sound/                    Top-level package
        __init__.py       Initialize the sound package
        main.py           I add this Bob to show where the main.py

        formats/          Subpoackage for the file format conversions
                __init__.py
                wavread.py
                wavwrite.py
                aiffread.py
                auread.py
                auwrite.py
                ...

        effects/           Subpackage for sound effect
                __init__.py
                echo.py
                surround.py
                reverse.py
                ...

        ui/                Subpackage for GUI form
                __init__.py
                MyForm.py

        It states that "The __init__.py files are required to make Python treat
the directories as containing packages".  They state later, "In the
simplest case, __init__.py can just be empty file, but it can also
execute initialization code for the package or set the __all__ variable.
Users of the the package can import individual modules from the package,
for example: 
     import sound.effects.echo."

"This loads the submodule sound.effects.echo.  It must be referenced
with its full name: 
     sound.effects.echo.echoFilter(input, output, delay=0.7, atten=4)"

        Let us say that I set my PYTHONPATH=/home/sysero/project/sound, which
is my working directory. In my working directory I have two
sub-directories called format and effects.  In my main.py I have:

import sound.effects.echo

sound.effects.echo.echoFilter(input, output, delay=0.7, atten=4)

I think that python will look in all my sub-directory in my working
directory for the __init__.py and see if inside the script if it has an
from statement that has:

from sound.effects.echo import echoFilter
   or should it be
from sound.effects import echo
???

        Then Python will load the echo module that is within the effects
directory.  To put it in another way the effects directory is in a way a
module that contains other modules and the __init__.py is to list the
modules and classes within the module. This is why one does not need to
include all the sub-directories in the PYTHONPATH.  Am I correct about
this idea?  

        I also think, if this is correct that you must have a:
   from sound.effects.echo import echoFilter
 
in my module like main.py to access my object 
   echoFilter(input, output, delay=0.7, atten=4)

and in the sub-directory effects in my __init__.py the line:
   from sound.effects import echo
???

        My next question is that in the folder ui I have a module MyForm.py
that uses the sub-directory formats wavread.py getWavFile class and the
sub-directory effects echo.py echoFilter class.  In my MyForm.py I would
use:

from sound.formats.wavread import getWavFile
from sound.effects.echo import echoFilter

getWavFile("sametest.wav")
echoFilter(input, output, delay=0.7, atten=4)

        the working dir is set in:
PYTHONPATH=/home/sysero/project/sound.  Python will look in all my
sub-directory formats and effects to check each __init__.py for my:

from sound.formats.wavread import getWavFile
from sound.effects.echo import echoFilter
   or 
from sound.formats.wavread import *
from sound.effects.echo import *
???

        I am going to send a Part II that will contiune this idea but using
dabo __init__.py and packages.  But I though it my be best to keep this
simple.

Thank you 
Bob




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: 
http://leafe.com/archives/byMID/1231256705.6812.104.ca...@sysero-rkm-laptop

Reply via email to