diff --git a/special-method-names.html b/special-method-names.html index 94bdd89..3f6a11c 100644 --- a/special-method-names.html +++ b/special-method-names.html @@ -286,8 +286,8 @@ class FieldStorage: return len(self.keys())
  1. Once you create an instance of the cgi.FieldStorage class, you can use the “in” operator to check whether a particular parameter was included in the query string. -
  2. The __contains__() method is the magic that makes this work. -
  3. When you say if 'q' in fs, Python looks for the __contains__() method on the fs object, which is defined in cgi.py. The value 'q' is passed into the __contains__() method as the key argument. +
  4. The __contains__() method is the magic that makes this work. When you say if 'q' in fs, Python looks for the __contains__() method on the fs object, which is defined in cgi.py. The value 'q' is passed into the __contains__() method as the key argument. +
  5. The any() function takes a generator expression and returns True if the generator spits out any items. The any() function is smart enough to stop as soon as the first match is found.
  6. The same FieldStorage class also supports returning its length, so you can say len(fs) and it will call the __len__() method on the FieldStorage class to return the number of query parameters that it identified.
  7. The self.keys() method checks whether self.list is None, so the __len__ method doesn’t need to duplicate this error checking.