Python submodules and name imports

F

Frank Aune

Hi,

First take a look at:

http://www.network-theory.co.uk/docs/pytut/Packages.html

as I will use this module file layout as an example.

If I want to do the following:

from Sound import Effects
....
Effects.echo.echofilte(bla bla)

What will Sound/Effects/__init__.py need to contain then? I tried to define
the __all__ = ['echo','surround','reverse'] parameter in the init file, but
this only seems to be effective for " .. import *" statements.

Is the correct way of accomplishing this to explicitly import the submodules
in sound/Effects/__init__.py? I'm looking for the "official" way of doing
this.

Thank you,
Frank Aune
 
?

=?iso-8859-1?B?UOFkcmFpZw==?=

Hi,

First take a look at:

http://www.network-theory.co.uk/docs/pytut/Packages.html

as I will use this module file layout as an example.

If I want to do the following:

from Sound import Effects
...
Effects.echo.echofilte(bla bla)

What will Sound/Effects/__init__.py need to contain then? I tried to define
the __all__ = ['echo','surround','reverse'] parameter in the init file, but
this only seems to be effective for " .. import *" statements.

Is the correct way of accomplishing this to explicitly import the submodules
in sound/Effects/__init__.py? I'm looking for the "official" way of doing
this.

Thank you,
Frank Aune

You can put 'import echo' into sound/Effects/__init__.py. This is a
widespread practice. You could also put 'from echo import *' into the
file, if you wanted to have a single namespace for all methods in
Effects.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top