Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
68a57ac4
Commit
68a57ac4
authored
Jun 11, 2007
by
Neal Norwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SF #1734732, lower case the module names per PEP 8.
Will backport.
parent
478b99b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
26 deletions
+26
-26
Doc/tut/tut.tex
Doc/tut/tut.tex
+26
-26
No files found.
Doc/tut/tut.tex
View file @
68a57ac4
...
...
@@ -2758,9 +2758,9 @@ possible structure for your package (expressed in terms of a
hierarchical filesystem
)
:
\begin
{
verbatim
}
S
ound
/
Top
-
level package
s
ound
/
Top
-
level package
__
init
__
.py Initialize the sound package
F
ormats
/
Subpackage for file format conversions
f
ormats
/
Subpackage for file format conversions
__
init
__
.py
wavread.py
wavwrite.py
...
...
@@ -2769,13 +2769,13 @@ Sound/ Top-level package
auread.py
auwrite.py
...
E
ffects
/
Subpackage for sound effects
e
ffects
/
Subpackage for sound effects
__
init
__
.py
echo.py
surround.py
reverse.py
...
F
ilters
/
Subpackage for filters
f
ilters
/
Subpackage for filters
__
init
__
.py
equalizer.py
vocoder.py
...
...
@@ -2798,20 +2798,20 @@ Users of the package can import individual modules from the
package, for example:
\begin
{
verbatim
}
import
Sound.E
ffects.echo
import
sound.e
ffects.echo
\end
{
verbatim
}
This loads the submodule
\module
{
Sound.E
ffects.echo
}
. It must be referenced
This loads the submodule
\module
{
sound.e
ffects.echo
}
. It must be referenced
with its full name.
\begin
{
verbatim
}
Sound.E
ffects.echo.echofilter
(
input, output, delay
=
0
.
7
, atten
=
4
)
sound.e
ffects.echo.echofilter
(
input, output, delay
=
0
.
7
, atten
=
4
)
\end
{
verbatim
}
An alternative way of importing the submodule is:
\begin
{
verbatim
}
from
Sound.E
ffects import echo
from
sound.e
ffects import echo
\end
{
verbatim
}
This also loads the submodule
\module
{
echo
}
, and makes it available without
...
...
@@ -2824,7 +2824,7 @@ echo.echofilter(input, output, delay=0.7, atten=4)
Yet another variation is to import the desired function or variable directly:
\begin
{
verbatim
}
from
Sound.E
ffects.echo import echofilter
from
sound.e
ffects.echo import echofilter
\end
{
verbatim
}
Again, this loads the submodule
\module
{
echo
}
, but this makes its function
...
...
@@ -2851,7 +2851,7 @@ class or function or variable defined in the previous item.
%The \code{__all__} Attribute
\ttindex
{__
all
__}
Now what happens when the user writes
\code
{
from
Sound.E
ffects import
Now what happens when the user writes
\code
{
from
sound.e
ffects import
*
}
? Ideally, one would hope that this somehow goes out to the
filesystem, finds which submodules are present in the package, and
imports them all. Unfortunately, this operation does not work very
...
...
@@ -2873,19 +2873,19 @@ encountered. It is up to the package author to keep this list
up
-
to
-
date when a new version of the package is released. Package
authors may also decide not to support it, if they don't see a use for
importing
*
from their package. For example, the file
\file
{
Sounds
/
E
ffects
/
__
init
__
.py
}
could contain the following code:
\file
{
sounds
/
e
ffects
/
__
init
__
.py
}
could contain the following code:
\begin
{
verbatim
}
__
all
__
=
[
"echo", "surround", "reverse"
]
\end
{
verbatim
}
This would mean that
\code
{
from
Sound.E
ffects import
*
}
would
import the three named submodules of the
\module
{
S
ound
}
package.
This would mean that
\code
{
from
sound.e
ffects import
*
}
would
import the three named submodules of the
\module
{
s
ound
}
package.
If
\code
{__
all
__}
is not defined, the statement
\code
{
from
Sound.E
ffects
If
\code
{__
all
__}
is not defined, the statement
\code
{
from
sound.e
ffects
import
*
}
does
\emph
{
not
}
import all submodules from the package
\module
{
Sound.E
ffects
}
into the current namespace; it only ensures that the
package
\module
{
Sound.E
ffects
}
has been imported
(
possibly running any
\module
{
sound.e
ffects
}
into the current namespace; it only ensures that the
package
\module
{
sound.e
ffects
}
has been imported
(
possibly running any
initialization code in
\file
{__
init
__
.py
}
)
and then imports whatever names are
defined in the package. This includes any names defined
(
and
submodules explicitly loaded
)
by
\file
{__
init
__
.py
}
. It also includes any
...
...
@@ -2893,14 +2893,14 @@ submodules of the package that were explicitly loaded by previous
import statements. Consider this code:
\begin
{
verbatim
}
import
Sound.E
ffects.echo
import
Sound.E
ffects.surround
from
Sound.E
ffects import
*
import
sound.e
ffects.echo
import
sound.e
ffects.surround
from
sound.e
ffects import
*
\end
{
verbatim
}
In this example, the echo and surround modules are imported in the
current namespace because they are defined in the
\module
{
Sound.E
ffects
}
package when the
\code
{
from...import
}
statement
\module
{
sound.e
ffects
}
package when the
\code
{
from...import
}
statement
is executed.
(
This also works when
\code
{__
all
__}
is defined.
)
Note that in general the practice of importing
\code
{
*
}
from a module or
...
...
@@ -2928,12 +2928,12 @@ which the current module is a submodule), the \keyword{import}
statement looks for a top
-
level module with the given name.
When packages are structured into subpackages
(
as with the
\module
{
S
ound
}
package in the example
)
, there's no shortcut to refer
\module
{
s
ound
}
package in the example
)
, there's no shortcut to refer
to submodules of sibling packages
-
the full name of the subpackage
must be used. For example, if the module
\module
{
Sound.F
ilters.vocoder
}
needs to use the
\module
{
echo
}
module
in the
\module
{
Sound.E
ffects
}
package, it can use
\code
{
from
Sound.E
ffects import echo
}
.
\module
{
sound.f
ilters.vocoder
}
needs to use the
\module
{
echo
}
module
in the
\module
{
sound.e
ffects
}
package, it can use
\code
{
from
sound.e
ffects import echo
}
.
Starting with Python
2
.
5
, in addition to the implicit relative imports
described above, you can write explicit relative imports with the
...
...
@@ -2944,8 +2944,8 @@ module for example, you might use:
\begin
{
verbatim
}
from . import echo
from .. import
F
ormats
from ..
F
ilters import equalizer
from .. import
f
ormats
from ..
f
ilters import equalizer
\end
{
verbatim
}
Note that both explicit and implicit relative imports are based on the
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment