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
304f9ff7
Kaydet (Commit)
304f9ff7
authored
Tem 29, 2007
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Clarify PEP 343 description.
üst
8eab424f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
9 deletions
+18
-9
whatsnew25.tex
Doc/whatsnew/whatsnew25.tex
+18
-9
No files found.
Doc/whatsnew/whatsnew25.tex
Dosyayı görüntüle @
304f9ff7
...
@@ -640,15 +640,20 @@ with expression [as variable]:
...
@@ -640,15 +640,20 @@ with expression [as variable]:
\end{verbatim}
\end{verbatim}
The expression is evaluated, and it should result in an object that
The expression is evaluated, and it should result in an object that
supports the context management protocol. This object may return a
supports the context management protocol (that is, has
\method
{__
enter
__
()
}
value that can optionally be bound to the name
\var
{
variable
}
. (Note
and
\method
{__
exit
__
()
}
methods.
carefully that
\var
{
variable
}
is
\emph
{
not
}
assigned the result of
\var
{
expression
}
.) The object can then run set-up code
before
\var
{
with-block
}
is executed and some clean-up code
is executed after the block is done, even if the block raised an exception.
To enable the statement in Python 2.5, you need
The object's
\method
{__
enter
__
()
}
is called before
\var
{
with-block
}
is
to add the following directive to your module:
executed and therefore can run set-up code. It also may return a value
that is bound to the name
\var
{
variable
}
, if given. (Note carefully
that
\var
{
variable
}
is
\emph
{
not
}
assigned the result of
\var
{
expression
}
.)
After execution of the
\var
{
with-block
}
is finished, the object's
\method
{__
exit
__
()
}
method is called, even if the block raised an exception,
and can therefore run clean-up code.
To enable the statement in Python 2.5, you need to add the following
directive to your module:
\begin{verbatim}
\begin{verbatim}
from
__
future
__
import with
_
statement
from
__
future
__
import with
_
statement
...
@@ -668,9 +673,13 @@ with open('/etc/passwd', 'r') as f:
...
@@ -668,9 +673,13 @@ with open('/etc/passwd', 'r') as f:
\end{verbatim}
\end{verbatim}
After this statement has executed, the file object in
\var
{
f
}
will
After this statement has executed, the file object in
\var
{
f
}
will
have been automatically closed, even if the
'for'
loop
have been automatically closed, even if the
\keyword
{
for
}
loop
raised an exception part-way through the block.
raised an exception part-way through the block.
\note
{
In this case,
\var
{
f
}
is the same object created by
\function
{
open()
}
, because
\method
{
file.
__
enter
__
()
}
returns
\var
{
self
}
.
}
The
\module
{
threading
}
module's locks and condition variables
The
\module
{
threading
}
module's locks and condition variables
also support the '
\keyword
{
with
}
' statement:
also support the '
\keyword
{
with
}
' statement:
...
...
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