File: //usr/local/ssl/local/ssl/lib/python2.4/Demo/classes/Range.pyo
mò
‚=5Dc @ sP d Z d „ Z d „ Z d f d „ ƒ YZ d „ Z e d j o e ƒ n d S( s Example of a generator: re-implement the built-in range function
without actually constructing the list of values.
OldStyleRange is coded in the way required to work in a 'for' loop before
iterators were introduced into the language; using __getitem__ and __len__ .
c C sñ yË t | ƒ d j o d t | d ƒ d f Snš t | ƒ d j o% t | d ƒ t | d ƒ d f Snb t | ƒ d j o9 | d d j o t d ƒ ‚ n t d „ | Dƒ ƒ Sn t d t | ƒ ƒ ‚ Wn t j
o t d ƒ ‚ n Xd S(
sg Take list of arguments and extract/create proper start, stop, and step
values and return in a tuplei i i i s step argument must not be zeroc c s x | ] } t | ƒ Vq Wd S( N( t [outmost-iterable]t xt int( R R ( ( t( /usr/lib/python2.4/Demo/classes/Range.pyt <generator expression> s s$ range() accepts 1-3 arguments, givensA range() arguments must be numbers or strings representing numbersN( t lent arglistR t
ValueErrort tuplet TypeError( R ( ( R t
handleargs s %c g sB t | ƒ \ } } } | } x | | j o | V| | 7} q Wd S( s, Function to implement 'range' as a generatorN( R
t at startt stopt stept value( R R
R R R ( ( R t genrange s
t oldrangec B s2 t Z d Z d „ Z d „ Z d „ Z d „ Z RS( s Class implementing a range object.
To the user the instances feel like immutable sequences
(and you can't concatenate or slice them)
Done using the old way (pre-iterators; __len__ and __getitem__) to have an
object be used by a 'for' loop.
c G sE t | ƒ \ | _ | _ | _ t d | i | i | i ƒ | _ d S( s„ Initialize start, stop, and step values along with calculating the
nubmer of values (what __len__ will return) in the rangei N( R
R t selfR R
R t maxR ( R R ( ( R t __init__, s c C s d | i | i | i f S( s- implement repr(x) which is also used by prints range(%r, %r, %r)N( R R R
R ( R ( ( R t __repr__2 s c C s | i S( s implement len(x)N( R R ( R ( ( R t __len__6 s c C sD d | j o
| i j n o | i | i | Sn
t d ‚ d S( s implement x[i]i s range[i] index out of rangeN( t iR R R R t
IndexError( R R ( ( R t __getitem__: s !( t __name__t
__module__t __doc__R R R R ( ( ( R R "