Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
94a98e4f
Kaydet (Commit)
94a98e4f
authored
Tem 06, 2006
tarafından
Nick Coghlan
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Update the tutorial section on relative imports
üst
56829d5b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
8 deletions
+25
-8
tut.tex
Doc/tut/tut.tex
+25
-8
No files found.
Doc/tut/tut.tex
Dosyayı görüntüle @
94a98e4f
...
@@ -2919,14 +2919,13 @@ submodules with the same name from different packages.
...
@@ -2919,14 +2919,13 @@ submodules with the same name from different packages.
The submodules often need to refer to each other. For example, the
The submodules often need to refer to each other. For example, the
\module
{
surround
}
module might use the
\module
{
echo
}
module. In fact,
\module
{
surround
}
module might use the
\module
{
echo
}
module. In fact,
such references
such references are so common that the
\keyword
{
import
}
statement
are so common that the
\keyword
{
import
}
statement first looks in the
first looks in the containing package before looking in the standard
containing package before looking in the standard module search path.
module search path. Thus, the
\module
{
surround
}
module can simply use
Thus, the surround module can simply use
\code
{
import echo
}
or
\code
{
import echo
}
or
\code
{
from echo import echofilter
}
. If the
\code
{
from echo import echofilter
}
. If the imported module is not
imported module is not found in the current package
(
the package of
found in the current package
(
the package of which the current module
which the current module is a submodule
)
, the
\keyword
{
import
}
is a submodule
)
, the
\keyword
{
import
}
statement looks for a top
-
level
statement looks for a top
-
level module with the given name.
module with the given name.
When packages are structured into subpackages
(
as with the
When packages are structured into subpackages
(
as with the
\module
{
Sound
}
package in the example
)
, there's no shortcut to refer
\module
{
Sound
}
package in the example
)
, there's no shortcut to refer
...
@@ -2936,6 +2935,24 @@ must be used. For example, if the module
...
@@ -2936,6 +2935,24 @@ must be used. For example, if the module
in the
\module
{
Sound.Effects
}
package, it can use
\code
{
from
in the
\module
{
Sound.Effects
}
package, it can use
\code
{
from
Sound.Effects import echo
}
.
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
\code
{
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
\module
{
surround
}
module for example, you might use:
\begin
{
verbatim
}
from . import echo
from .. import Formats
from ..Filters import equalizer
\end
{
verbatim
}
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
\code
{
"
__
main
__
"
}
, modules intended for use as the main module of a
Python application should always use absolute imports.
\subsection
{
Packages in Multiple Directories
}
\subsection
{
Packages in Multiple Directories
}
Packages support one more special attribute,
\member
{__
path
__}
. This
Packages support one more special attribute,
\member
{__
path
__}
. This
...
...
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