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) '. '}
x = MyClass()
-x.__init__()
+x.__init__()
repr(x)
-x.__repr__()
+x.__repr__()
str(x)
+str(x)
x.__str__()
x.__bytes__()
format(x, format_spec)
+format(x, format_spec)
x.__format__(format_spec)
with BlockPython 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.