mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Remove many "versionchanged" items that didn't use the official markup,
but just some text embedded in the docs. Also remove paragraph about implicit relative imports from tutorial.
This commit is contained in:
parent
c73728373c
commit
e6bcc9145e
52 changed files with 147 additions and 469 deletions
|
@ -344,8 +344,7 @@ occurred in the :keyword:`try` clause and has not been handled by an
|
|||
been executed. The :keyword:`finally` clause is also executed "on the way out"
|
||||
when any other clause of the :keyword:`try` statement is left via a
|
||||
:keyword:`break`, :keyword:`continue` or :keyword:`return` statement. A more
|
||||
complicated example (having :keyword:`except` and :keyword:`finally` clauses in
|
||||
the same :keyword:`try` statement works as of Python 2.5)::
|
||||
complicated example::
|
||||
|
||||
>>> def divide(x, y):
|
||||
... try:
|
||||
|
|
|
@ -493,35 +493,24 @@ packages.
|
|||
Intra-package References
|
||||
------------------------
|
||||
|
||||
The submodules often need to refer to each other. For example, the
|
||||
:mod:`surround` module might use the :mod:`echo` module. In fact, such
|
||||
references are so common that the :keyword:`import` statement first looks in the
|
||||
containing package before looking in the standard module search path. Thus, the
|
||||
:mod:`surround` module can simply use ``import echo`` or ``from echo import
|
||||
echofilter``. If the imported module is not found in the current package (the
|
||||
package of 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 :mod:`sound` package
|
||||
in the example), you can use absolute imports to refer to submodules of siblings
|
||||
packages. For example, if the module :mod:`sound.filters.vocoder` needs to use
|
||||
the :mod:`echo` module in the :mod:`sound.effects` package, it can use ``from
|
||||
sound.effects import echo``.
|
||||
|
||||
Starting with Python 2.5, in addition to the implicit relative imports described
|
||||
above, you can write explicit relative imports with the ``from module import
|
||||
name`` form of import statement. These explicit relative imports use leading
|
||||
dots to indicate the current and parent packages involved in the relative
|
||||
import. From the :mod:`surround` module for example, you might use::
|
||||
You can also write relative imports, with the ``from module import name`` form
|
||||
of import statement. These imports use leading dots to indicate the current and
|
||||
parent packages involved in the relative import. From the :mod:`surround`
|
||||
module for example, you might use::
|
||||
|
||||
from . import echo
|
||||
from .. import formats
|
||||
from ..filters import equalizer
|
||||
|
||||
Note that both explicit and implicit relative imports are based on the name of
|
||||
the current module. Since the name of the main module is always ``"__main__"``,
|
||||
modules intended for use as the main module of a Python application should
|
||||
always use absolute imports.
|
||||
Note that relative imports are based on the name of the current module. Since
|
||||
the name of the main module is always ``"__main__"``, modules intended for use
|
||||
as the main module of a Python application must always use absolute imports.
|
||||
|
||||
|
||||
Packages in Multiple Directories
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue