Re: [Python-3000] what do I use in place of reduce?

2008-04-24 Thread Marcin ‘Qrczak’ Kowalczyk
Dnia 24-04-2008, czw o godzinie 07:40 +0200, "Martin v. Löwis" pisze: > In this case, I wouldn't use a loop at all: > > py> time=1901248 > py> minutes,seconds = divmod(time, 60) > py> hours,minutes = divmod(minutes, 60) > py> days,hours = divmod(hours,24) > py> seconds,minutes,hours,days > (28, 7

Re: [Python-3000] help() broken?

2008-04-24 Thread Amaury Forgeot d'Arc
Humberto Diogenes wrote: > Hi, > > It seems that help() doesn't work on instances in py3k. > > Is this what this ticket is about? > http://bugs.python.org/issue1883 > > > Python 3.0a4+ (py3k:62469M, Apr 23 2008, 20:46:05) > [GCC 4.0.1 (Apple Inc. build 5465)] on darwin > Type "help", "copy

[Python-3000] Assert syntax change...

2008-04-24 Thread Charles Merriam
Hello All, I expect it is far to late for this, and I still wanted to make the issue known. The assert statement is one of the few remaining Python statements where it (1) does not use parenthesis and (2) takes multiple arguments. This leads to the common, hard to detect, programming error:

[Python-3000] Using range()

2008-04-24 Thread Facundo Batista
Hi all! Used to be able to do this... >>> l = (x for x in range(10)) >>> l.__next__() 0 >>> l.__next__() 1 ...I tried the following: >>> r = range(5) >>> r range(0, 5) >>> r.__next__ Traceback (most recent call last): ... AttributeError: 'range' object has no attribute '__next__' Which is the

Re: [Python-3000] Using range()

2008-04-24 Thread Martin v. Löwis
> Which is the normal way to "consume" a range object, item by item? The normal way is a for loop. The advanced way of invoking some method on the object (i.e. emulating the for loop) is to first create an iterator from the range object. You can't consume the range itself: it will always contain

Re: [Python-3000] Using range()

2008-04-24 Thread Facundo Batista
2008/4/24, "Martin v. Löwis" <[EMAIL PROTECTED]>: > The advanced way of invoking some method on the object (i.e. emulating > the for loop) is to first create an iterator from the range object. > You can't consume the range itself: it will always contain the same > numbers - just like you can't

Re: [Python-3000] Using range()

2008-04-24 Thread Mark Dickinson
On Thu, Apr 24, 2008 at 10:58 AM, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > r = range(1000) > r[0] > > Traceback (most recent call last): > > File "", line 1, in > > OverflowError: Python int too large to convert to C ssize_t > > > > This is a bug, right? > >

Re: [Python-3000] Using range()

2008-04-24 Thread Martin v. Löwis
>> > This is a bug, right? >> >> I'd call it an implementation limitation. > > This is because I'm in a 32 bit machine? Right. The assumption is that you typically use the range elements to index into some collections, and you can't have collections with more than 2**32 elements (actually, addre

Re: [Python-3000] Using range()

2008-04-24 Thread Nick Coghlan
Martin v. Löwis wrote: Which is the normal way to "consume" a range object, item by item? The normal way is a for loop. The advanced way of invoking some method on the object (i.e. emulating the for loop) is to first create an iterator from the range object. You can't consume the range itself:

Re: [Python-3000] Using range()

2008-04-24 Thread Mark Dickinson
On Thu, Apr 24, 2008 at 11:37 AM, Nick Coghlan <[EMAIL PROTECTED]> wrote: > While I could understand a 'must fit in ssize_t' limitation on the index > passed to the range object (or conceivably even on the value returned, > although that would be a little odd), that isn't happening in the example

Re: [Python-3000] Using range()

2008-04-24 Thread Martin v. Löwis
> It is a bit surprising, especially given > that the following works: > r = range(10**19-100, 10**19) r[0] > 900 The original example fails because range_length() overflows in range_item. Given that range_item is "almost" there, it's probably not as difficult to fix th

Re: [Python-3000] Using range()

2008-04-24 Thread Nick Coghlan
Martin v. Löwis wrote: > This is a bug, right? I'd call it an implementation limitation. This is because I'm in a 32 bit machine? Right. The assumption is that you typically use the range elements to index into some collections, and you can't have collections with more than 2**32 elements (a

Re: [Python-3000] Using range()

2008-04-24 Thread Martin v. Löwis
> Where is that OverflowError coming from? It computes the length of the range, to find out whether the index is out of range. Computing the length then raises the exception, as it uses range_length, not range_length_obj. Regards, Martin ___ Python-3

Re: [Python-3000] what do I use in place of reduce?

2008-04-24 Thread Martin v. Löwis
> On Wed, Apr 23, 2008 at 10:40 PM, "Martin v. Löwis" <[EMAIL PROTECTED] > > wrote: > > py> time % 60, time//60%60, time//3600%24, time//(3600*24) > (28, 7, 0, 22) > > the 3600 and 3600*24 was what I was trying to avoid. This is getting off-topic, so you don't n

Re: [Python-3000] Assert syntax change...

2008-04-24 Thread Guido van Rossum
I sympathize with the sentiment, but 'as' is the wrong keyword; there is no assignment to the thing on its right hand side like there is in all other places where it is used in the syntax (import-as, with-as, except-as). Also, have you actually tried this in 3.0? It prints a nice SytaxWarning mess

Re: [Python-3000] what do I use in place of reduce?

2008-04-24 Thread Nicholas T
On Thu, Apr 24, 2008 at 11:23 AM, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > This is getting off-topic, so you don't need to answer; I still ask: > Why??? yes I know, apologies for not mailing the right list. I'll try to do so next time. Dividing the previous result seems more logical: minute

Re: [Python-3000] what do I use in place of reduce?

2008-04-24 Thread Nicholas T
On Wed, Apr 23, 2008 at 10:35 PM, Alex Martelli <[EMAIL PROTECTED]> wrote: > Is 119 vs 117 characters "a LOT of verbosity"...?! OK, then what about...: the reduce is actually 69 *and only one line* if you don't need it in a function. You can't put the dhms2 in a function unless you want to leak

Re: [Python-3000] Using range()

2008-04-24 Thread Mark Dickinson
On Thu, Apr 24, 2008 at 11:50 AM, Nick Coghlan <[EMAIL PROTECTED]> wrote: > There's definitely some bugs in this area of the range object code though: > > >>> x = range(2**33, 2) > >>> len(x) > 0 > >>> x[0] > Traceback (most recent call last): > File "", line 1, in > IndexError: range object ind

Re: [Python-3000] Using range()

2008-04-24 Thread Guido van Rossum
On Thu, Apr 24, 2008 at 1:01 PM, Mark Dickinson <[EMAIL PROTECTED]> wrote: > It seems to me that there are two reasonable behaviours > for range(a, b) when b is less than a: return an 'empty' range, > as in the example above, or raise a ValueError; Don't even think about suggesting to change this

Re: [Python-3000] Assert syntax change...

2008-04-24 Thread Mikhail Glushenkov
Hello, Guido van Rossum python.org> writes: > > I sympathize with the sentiment, but 'as' is the wrong keyword; Why not make ``assert`` a built-in function then? ___ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/list

Re: [Python-3000] Assert syntax change...

2008-04-24 Thread Guido van Rossum
On Thu, Apr 24, 2008 at 1:51 PM, Mikhail Glushenkov > Why not make ``assert`` a built-in function then? Because then it can't be disabled by the compiler in -O mode. -- --Guido van Rossum (home page: http://www.python.org/~guido/) ___ Python-3000 mail

Re: [Python-3000] Assert syntax change...

2008-04-24 Thread Charles Merriam
On Thu, Apr 24, 2008 at 2:01 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On Thu, Apr 24, 2008 at 1:51 PM, Mikhail Glushenkov > > Why not make ``assert`` a built-in function then? > Because then it can't be disabled by the compiler in -O mode. A reasonable conclusion, but needs better reaso

Re: [Python-3000] what do I use in place of reduce?

2008-04-24 Thread Brett Cannon
[SNIP] > > > In any case, writing multiple lines is good, writing a single line only > > is bad. > I don't agree. If it's code you want to write once and never look at again, > having it out of the way can be nice. But this is Python; explicit is better than implicit. You write one-liners on the w

Re: [Python-3000] Assert syntax change...

2008-04-24 Thread Greg Ewing
Charles Merriam wrote: It would be great to change assert from: assert_stmt::= "assert" expression ["," expression] To: assert_stmt::= "assert" expression ["as" expression] I don't think "as" is the right word to use here... maybe assert else That is, w

Re: [Python-3000] Using range()

2008-04-24 Thread Nick Coghlan
Mark Dickinson wrote: On Thu, Apr 24, 2008 at 11:50 AM, Nick Coghlan <[EMAIL PROTECTED] > wrote: There's definitely some bugs in this area of the range object code though: >>> x = range(2**33, 2) >>> len(x) 0 >>> x[0] Traceback (most re

Re: [Python-3000] Assert syntax change...

2008-04-24 Thread Nick Coghlan
Charles Merriam wrote: On Thu, Apr 24, 2008 at 2:01 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote: On Thu, Apr 24, 2008 at 1:51 PM, Mikhail Glushenkov Why not make ``assert`` a built-in function then? Because then it can't be disabled by the compiler in -O mode. A reasonable conclusion, b