Re: [Tutor] Workaround for limitation in xrange()?

2006-10-11 Thread Kent Johnson
Alan Gauld wrote: Dick Moores [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Encapsulate the while loop in a generator: def count(limit): n=0 while nlimit: yield n n += 1 All 3 are essentially the same, aren't they. Which makes me feel even dumber, because I

[Tutor] Workaround for limitation in xrange()?

2006-10-10 Thread Dick Moores
for x in xrange(2**31): pass Traceback (most recent call last): File pyshell#16, line 1, in module for x in xrange(2**31): OverflowError: long int too large to convert to int I can think of 2 workarounds for this 2**31 limitation in xrange(). Use a while loop instead. Or use 2

Re: [Tutor] Workaround for limitation in xrange()?

2006-10-10 Thread Kent Johnson
Dick Moores wrote: for x in xrange(2**31): pass Traceback (most recent call last): File pyshell#16, line 1, in module for x in xrange(2**31): OverflowError: long int too large to convert to int I can think of 2 workarounds for this 2**31 limitation in xrange(). Use a

Re: [Tutor] Workaround for limitation in xrange()?

2006-10-10 Thread Andrei
Dick Moores rdm at rcblue.com writes: snip I can think of 2 workarounds for this 2**31 limitation in xrange(). Use a while loop instead. Or use 2 or more for loops, keeping the number of cycles in each under 2**31. Are there others? Write your own iterator: def hugerange(minval,

Re: [Tutor] Workaround for limitation in xrange()?

2006-10-10 Thread Danny Yoo
for x in xrange(2**31): pass Traceback (most recent call last): File pyshell#16, line 1, in module for x in xrange(2**31): OverflowError: long int too large to convert to int Hi Dick, Hmmm... I'd consider this a misfeature in the implementation. Apparently xrange (and

Re: [Tutor] Workaround for limitation in xrange()?

2006-10-10 Thread Dick Moores
for x in xrange(2**31): pass Traceback (most recent call last): File pyshell#16, line 1, in module for x in xrange(2**31): OverflowError: long int too large to convert to int Here are the suggestions I've received: Danny's # def myxrange(m, n=None, skip=1):

Re: [Tutor] Workaround for limitation in xrange()?

2006-10-10 Thread Kent Johnson
Dick Moores wrote: Here are the suggestions I've received: snipped All 3 are essentially the same, aren't they. Which makes me feel even dumber, because I don't understand any of them. I've consulted 3 books, and still don't understand the use of yield. Yes, they are pretty much the

Re: [Tutor] Workaround for limitation in xrange()?

2006-10-10 Thread Marc Poulin
--- Dick Moores [EMAIL PROTECTED] wrote: Andrei's Write your own iterator: def hugerange(minval, maxval): ... val = minval ... while val maxval: ... yield val ... val += 1 All 3 are essentially the same, aren't they. Which makes me feel even dumber,

Re: [Tutor] Workaround for limitation in xrange()?

2006-10-10 Thread Dick Moores
At 11:34 AM 10/10/2006, Kent Johnson wrote: Dick Moores wrote: Here are the suggestions I've received: snipped All 3 are essentially the same, aren't they. Which makes me feel even dumber, because I don't understand any of them. I've consulted 3 books, and still don't understand the use of

Re: [Tutor] Workaround for limitation in xrange()?

2006-10-10 Thread Kent Johnson
Dick Moores wrote: At 11:34 AM 10/10/2006, Kent Johnson wrote: Dick Moores wrote: Here are the suggestions I've received: snipped All 3 are essentially the same, aren't they. Which makes me feel even dumber, because I don't understand any of them. I've consulted 3 books, and still

Re: [Tutor] Workaround for limitation in xrange()?

2006-10-10 Thread Dick Moores
At 12:31 PM 10/10/2006, Marc Poulin wrote: --- Dick Moores [EMAIL PROTECTED] wrote: Andrei's Write your own iterator: def hugerange(minval, maxval): ... val = minval ... while val maxval: ... yield val ... val += 1 All 3 are essentially the same,

Re: [Tutor] Workaround for limitation in xrange()?

2006-10-10 Thread Alan Gauld
Dick Moores [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Encapsulate the while loop in a generator: def count(limit): n=0 while nlimit: yield n n += 1 All 3 are essentially the same, aren't they. Which makes me feel even dumber, because I don't understand any