@@ -290,19 +290,18 @@ are always available. They are listed here in alphabetical order.
290290 The resulting list is sorted alphabetically. For example:
291291
292292 >>> import struct
293- >>> dir () # doctest: +SKIP
293+ >>> dir () # show the names in the module namespace
294294 ['__builtins__', '__doc__', '__name__', 'struct']
295- >>> dir (struct) # doctest: +NORMALIZE_WHITESPACE
295+ >>> dir (struct) # show the names in the struct module
296296 ['Struct', '__builtins__', '__doc__', '__file__', '__name__',
297297 '__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into',
298298 'unpack', 'unpack_from']
299- >>> class Foo :
300- ... def __dir__ (self ):
301- ... return [" kan" , " ga" , " roo" ]
302- ...
303- >>> f = Foo()
304- >>> dir (f)
305- ['ga', 'kan', 'roo']
299+ >>> class Shape (object ):
300+ def __dir__(self):
301+ return ['area', 'perimeter', 'location']
302+ >>> s = Shape()
303+ >>> dir (s)
304+ ['area', 'perimeter', 'location']
306305
307306 .. note ::
308307
@@ -333,15 +332,21 @@ are always available. They are listed here in alphabetical order.
333332 :meth: `__next__ ` method of the iterator returned by :func: `enumerate ` returns a
334333 tuple containing a count (from *start * which defaults to 0) and the
335334 corresponding value obtained from iterating over *iterable *.
336- :func: `enumerate ` is useful for obtaining an indexed series: ``(0, seq[0]) ``,
337- ``(1, seq[1]) ``, ``(2, seq[2]) ``, .... For example:
338335
339- >>> for i, season in enumerate ([' Spring' , ' Summer' , ' Fall' , ' Winter' ]):
340- ... print (i, season)
341- 0 Spring
342- 1 Summer
343- 2 Fall
344- 3 Winter
336+ >>> for i, season in enumerate (' Spring Summer Fall Winter' .split(), start = 1 ):
337+ print(i, season)
338+ 1 Spring
339+ 2 Summer
340+ 3 Fall
341+ 4 Winter
342+
343+ Equivalent to::
344+
345+ def enumerate(sequence, start=0):
346+ n = start
347+ for elem in sequence:
348+ yield n, elem
349+ n += 1
345350
346351
347352.. function :: eval(expression, globals=None, locals=None)
@@ -652,10 +657,10 @@ are always available. They are listed here in alphabetical order.
652657
653658 One useful application of the second form of :func: `iter ` is to read lines of
654659 a file until a certain line is reached. The following example reads a file
655- until `` "STOP" `` is reached: ::
660+ until the :meth: ` readline ` method returns an empty string ::
656661
657- with open(" mydata.txt" ) as fp:
658- for line in iter(fp.readline, "STOP" ):
662+ with open(' mydata.txt' ) as fp:
663+ for line in iter(fp.readline, '' ):
659664 process_line(line)
660665
661666
@@ -1169,8 +1174,9 @@ are always available. They are listed here in alphabetical order.
11691174 It can be called either on the class (such as ``C.f() ``) or on an instance (such
11701175 as ``C().f() ``). The instance is ignored except for its class.
11711176
1172- Static methods in Python are similar to those found in Java or C++. For a more
1173- advanced concept, see :func: `classmethod ` in this section.
1177+ Static methods in Python are similar to those found in Java or C++. Also see
1178+ :func: `classmethod ` for a variant that is useful for creating alternate class
1179+ constructors.
11741180
11751181 For more information on static methods, consult the documentation on the
11761182 standard type hierarchy in :ref: `types `.
@@ -1270,6 +1276,10 @@ are always available. They are listed here in alphabetical order.
12701276 references. The zero argument form automatically searches the stack frame
12711277 for the class (``__class__ ``) and the first argument.
12721278
1279+ For practical suggestions on how to design cooperative classes using
1280+ :func: `super `, see `guide to using super()
1281+ <http://rhettinger.wordpress.com/2011/05/26/super-considered-super/> `_.
1282+
12731283
12741284.. function :: tuple([iterable])
12751285
0 commit comments