From 1e01375257462baef28c6af53f8bc12d13ff5158 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Tue, 6 Oct 2009 11:50:30 -0400 Subject: [PATCH] add docs.python.org links for __init__ and friends; remove confusing intro sentence about the "with" keyword --- special-method-names.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/special-method-names.html b/special-method-names.html index 22a860b..4e47622 100644 --- a/special-method-names.html +++ b/special-method-names.html @@ -34,14 +34,14 @@ h3:before{counter-increment:h3;content:'B.' counter(h2) '.' counter(h3) '. '} ① to initialize an instance x = MyClass() -x.__init__() +x.__init__() ② the “official” representation as a string repr(x) -x.__repr__() +x.__repr__() ③ the “informal” value as a string -str(x) +str(x) x.__str__() ④ the “informal” value as a byte array @@ -49,7 +49,7 @@ h3:before{counter-increment:h3;content:'B.' counter(h2) '.' counter(h3) '. '} x.__bytes__() ⑤ the value as a formatted string -format(x, format_spec) +format(x, format_spec) x.__format__(format_spec)
    @@ -715,7 +715,7 @@ class FieldStorage:

    Classes That Can Be Used in a with Block

    -

    Python 3 supports the with statement, which allows you to access an object’s properties and methods without explicitly referencing the object every time. A with block defines a runtime context; you “enter” the context when you execute the with statement, and you “exit” the context after you execute the last statement in the block. +

    A with block defines a runtime context; you “enter” the context when you execute the with statement, and you “exit” the context after you execute the last statement in the block.

    Any class can be used in a with block; no special methods are required. The Python interpreter will automatically set up the runtime context and dispatch all the property and method lookups to your class. However, if you want your class to do something special upon entering or exiting a runtime context, you can define the following special methods.