range or xrange disallowed for big numbers

sismex01 at hebmex.com sismex01 at hebmex.com
Fri Oct 4 18:28:24 EDT 2002


> 
> Chad Netzer <cnetzer at mail.arc.nasa.gov> writes:
> 
> > Is there a reason (technical or philosophical) to disallow:
> > 
> >     range( 10000000000L, 10000000000L + 1L )
> > 
> > or 
> > 
> >     xrange( 10000000000L )
> > 
> > etc...?
> 

Defining your own is trivial:

from __future__ import generators

def XXRange(*args):
    if len(args) not in (1,2,3):
        raise ValueError("You must specify 1, 2 or 3 arguments only.")
    if len(args) == 1:
        start, finish, step = 0, args[0], 1
    elif len(args) == 2:
        start, finish = args
        finish = 1
    else:
        start, finish, step = args
    def _i(a,b,c):
        while a < b:
            yield a
            a += c
    return _i(start, finish, step)

Presto! And it can use floats if you wanna. :-)

-gustavo













More information about the Python-list mailing list