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
78d59d65
Kaydet (Commit)
78d59d65
authored
Tem 12, 2007
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Bug #1637365: add subsection about "__name__ == __main__" to the
Python tutorial. (backport from rev. 56306)
üst
f36e6a1a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
tut.tex
Doc/tut/tut.tex
+38
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/tut/tut.tex
Dosyayı görüntüle @
78d59d65
...
...
@@ -2522,6 +2522,44 @@ There is even a variant to import all names that a module defines:
This imports all names except those beginning with an underscore
(
\code
{_}
)
.
\subsection
{
Executing modules as scripts
\label
{
modulesAsScripts
}}
When you run a Python module with
\begin
{
verbatim
}
python fibo.py <arguments>
\end
{
verbatim
}
the code in the module will be executed, just as if you imported it, but
with the
\code
{__
name
__}
set to
\code
{
"
__
main
__
"
}
. That means that by
adding this code at the end of your module:
\begin
{
verbatim
}
if
__
name
__
==
"
__
main
__
":
import sys
fib
(
int
(
sys.argv
[
1
]))
\end
{
verbatim
}
you can make the file usable as a script as well as an importable module,
because the code that parses the command line only runs if the module is
executed as the ``main'' file:
\begin
{
verbatim
}
$
python fibo.py 50
1 1 2 3 5 8 13 21 34
\end{verbatim}
If the module is imported, the code is not run:
\begin{verbatim}
>>> import fibo
>>>
\end{verbatim}
This is often used either to provide a convenient user interface to a
module, or for testing purposes (running the module as a script executes
a test suite).
\subsection
{
The Module Search Path
\label
{
searchPath
}}
...
...
Misc/NEWS
Dosyayı görüntüle @
78d59d65
...
...
@@ -77,6 +77,9 @@ Extension Modules
Documentation
-------------
- Bug #1637365: add subsection about "__name__ == __main__" to the
Python tutorial.
- Bug #1569057: Document that calling file.next() on a file open for writing
has undefined behaviour. Backport of r54712.
...
...
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