From 58867ad769e431fb4271649ccb98767f791ff3e4 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Tue, 27 Jul 2010 14:00:06 -0400 Subject: [PATCH] sequence --> set [thanks P.P.] --- 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 63adebd..0821d09 100644 --- a/special-method-names.html +++ b/special-method-names.html @@ -18,7 +18,7 @@

 

Diving In

-

Throughout this book, you’ve seen examples of “special methods” — certain “magic” methods that Python invokes when you use certain syntax. Using special methods, your classes can act like sequences, like dictionaries, like functions, like iterators, or even like numbers. This appendix serves both as a reference for the special methods we’ve seen already and a brief introduction to some of the more esoteric ones. +

Throughout this book, you’ve seen examples of “special methods” — certain “magic” methods that Python invokes when you use certain syntax. Using special methods, your classes can act like sets, like dictionaries, like functions, like iterators, or even like numbers. This appendix serves both as a reference for the special methods we’ve seen already and a brief introduction to some of the more esoteric ones.

Basics

@@ -245,9 +245,9 @@ bytes = zef_file.read(12)
  • Given the first 12 bytes of a zip file, decrypt them by mapping the bytes to zd, in effect “calling” zd 12 times, which invokes the __call__() method 12 times, which updates its internal state and returns a resulting byte 12 times. -

    Classes That Act Like Sequences

    +

    Classes That Act Like Sets

    -

    If your class acts as a container for a set of values — that is, if it makes sense to ask whether your class “contains” a value — then it should probably define the following special methods that make it act like a sequence. +

    If your class acts as a container for a set of values — that is, if it makes sense to ask whether your class “contains” a value — then it should probably define the following special methods that make it act like a set.
    Notes @@ -264,7 +264,7 @@ bytes = zef_file.read(12) seq.__contains__(x)
    -

    The cgi module uses these methods in its FieldStorage class, which represents all of the form fields or query parameters submitted to a dynamic web page. +

    The cgi module uses these methods in its FieldStorage class, which represents all of the form fields or query parameters submitted to a dynamic web page.

    # A script which responds to http://example.com/search?q=cgi
     import cgi
    @@ -319,7 +319,7 @@ class FieldStorage:
     x.__missing__(nonexistent_key)
     
     
    -

    The FieldStorage class from the cgi module also defines these special methods, which means you can do things like this: +

    The FieldStorage class from the cgi module also defines these special methods, which means you can do things like this:

    # A script which responds to http://example.com/search?q=cgi
     import cgi