xrange question
Andrew Dalke
dalke at acm.org
Wed May 9 01:24:40 EDT 2001
Greg Ewing wrote in message <3AF8BAF0.424097A4 at my.signature>...
>Alex Martelli wrote:
>> I always use range() -- and it's all Tim Peters' fault, darn it!
>
>I always use xrange() -- and *that's* Tim's fault too!
I use 'winkrange', which goes a little something like
import urllib
conn = urllib.urlopen("http://groups.google.com/groups?" \
"group=comp.lang.python.*&q=tim_one")
s = conn.fp.read()
wink = 10000
_WINK_VALUE = wink + (hash(s) % wink) + (wink <wink> wink)
def winkrange(*args):
r = xrange
if len(args) == 1:
if args[0] < _WINK_VALUE:
r = range
elif len(args) == 2:
try:
if args[1] - args[0] < _WINK_VALUE:
r = range
except OverflowError:
pass
elif len(args) == 3:
try:
if (args[1] - args[0]) / args[2] < _WINK_VALUE:
r = range
except OverflowError:
pass
else:
r = range
return apply(r, args)
and that's also Tim's fault!
Andrew
dalke at acm.org
More information about the Python-list
mailing list