Re: [Python-Dev] Adding start to enumerate()

2008-05-13 Thread Duncan Booth
Steven D'Aprano [EMAIL PROTECTED] wrote: On Mon, 12 May 2008 08:20:51 am Georg Brandl wrote: I believe the following is a common use-case for enumerate() (at least, I've used it quite some times): for lineno, line in enumerate(fileobject): ... For this, it would be nice to have a

Re: [Python-Dev] Adding start to enumerate()

2008-05-13 Thread Steven D'Aprano
On Wed, 14 May 2008 12:25:01 am Guido van Rossum wrote: However I see no use for skipping items from the start, You've never had to deal with data where the first N items were special in some way? e.g. skipping over a header line in a file? I know I've written code like this before: it =

Re: [Python-Dev] Adding start to enumerate()

2008-05-13 Thread Facundo Batista
2008/5/13, Steven D'Aprano [EMAIL PROTECTED]: Perhaps what we need is a more flexible enumerate function? enumerate(iterable, start_at_index=0, count_from=0) +1 to provide both options: they're not intrusive (as I can keep using enumerate without those), and having both helps in the

Re: [Python-Dev] Adding start to enumerate()

2008-05-13 Thread Guido van Rossum
On Tue, May 13, 2008 at 11:53 AM, Steven D'Aprano [EMAIL PROTECTED] wrote: On Wed, 14 May 2008 12:25:01 am Guido van Rossum wrote: However I see no use for skipping items from the start, You've never had to deal with data where the first N items were special in some way? e.g. skipping

Re: [Python-Dev] Adding start to enumerate()

2008-05-13 Thread Guido van Rossum
On Tue, May 13, 2008 at 11:59 AM, Facundo Batista [EMAIL PROTECTED] wrote: 2008/5/13, Steven D'Aprano [EMAIL PROTECTED]: Perhaps what we need is a more flexible enumerate function? enumerate(iterable, start_at_index=0, count_from=0) +1 to provide both options: they're not intrusive

Re: [Python-Dev] Adding start to enumerate()

2008-05-13 Thread Georg Brandl
Guido van Rossum schrieb: On Tue, May 13, 2008 at 11:59 AM, Facundo Batista [EMAIL PROTECTED] wrote: 2008/5/13, Steven D'Aprano [EMAIL PROTECTED]: Perhaps what we need is a more flexible enumerate function? enumerate(iterable, start_at_index=0, count_from=0) +1 to provide both

Re: [Python-Dev] Adding start to enumerate()

2008-05-13 Thread Jesus Cea
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Greg Ewing wrote: | Steven D'Aprano wrote: | The only thing I can think of is printing lines with line numbers | | Parsing a file and wanting to be able to print | error messages with line numbers would seem to | be a fairly likely use. What is

Re: [Python-Dev] Adding start to enumerate()

2008-05-13 Thread Terry Reedy
Duncan Booth [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | | If you are generating paginated output then a function to generate an | arbitrary page would likely want to enumerate starting at some value larger | than one. | | Of course in that case you'll also want to skip part way

Re: [Python-Dev] Adding start to enumerate()

2008-05-13 Thread Steven D'Aprano
On Wed, 14 May 2008 05:01:20 am you wrote:  While slices are wonderfully useful things, they aren't panaceas.  They're not so useful with iterators, and they make a copy of the data, which can be problematic if there's a *lot* of it. That's why we have itertools.islice(). I always forget

Re: [Python-Dev] Adding start to enumerate()

2008-05-13 Thread Guido van Rossum
On Tue, May 13, 2008 at 3:11 PM, Steven D'Aprano [EMAIL PROTECTED] wrote: With iterators being such a fundamental part of Python these days, perhaps one day we'll see the functions in the itertools module become iterator methods, as happened with strings. But that's a discussion for

Re: [Python-Dev] Adding start to enumerate()

2008-05-13 Thread Greg Ewing
Steven D'Aprano wrote: With iterators being such a fundamental part of Python these days, perhaps one day we'll see the functions in the itertools module become iterator methods I hope not. The set of potential functions that operate on iterators is open-ended, and there's no reason to single

Re: [Python-Dev] Adding start to enumerate()

2008-05-13 Thread Nick Coghlan
Greg Ewing wrote: Steven D'Aprano wrote: With iterators being such a fundamental part of Python these days, perhaps one day we'll see the functions in the itertools module become iterator methods I hope not. The set of potential functions that operate on iterators is open-ended, and there's

Re: [Python-Dev] Adding start to enumerate()

2008-05-13 Thread Steve Holden
Steven D'Aprano wrote: [...] [tongue firmly in cheek] Perhaps what we need is a more flexible enumerate function? enumerate(iterable, start_at_index=0, count_from=0) Super idea. Then we can have a thread about whether it belongs in itertools or somewhere else. [...] Please take your tongue

Re: [Python-Dev] Adding start to enumerate()

2008-05-12 Thread Steve Holden
Steven D'Aprano wrote: On Mon, 12 May 2008 08:20:51 am Georg Brandl wrote: I believe the following is a common use-case for enumerate() (at least, I've used it quite some times): for lineno, line in enumerate(fileobject): ... For this, it would be nice to have a start parameter for

Re: [Python-Dev] Adding start to enumerate()

2008-05-12 Thread Nick Coghlan
Georg Brandl wrote: I believe the following is a common use-case for enumerate() (at least, I've used it quite some times): for lineno, line in enumerate(fileobject): ... For this, it would be nice to have a start parameter for enumerate(). The changes are minimal -- okay for 2.6? I'd

Re: [Python-Dev] Adding start to enumerate()

2008-05-12 Thread Terry Reedy
Nick Coghlan [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | I'd like to hear from Raymond before we do this. I'm pretty sure we had | a reason for *not* doing it that way in when enumerate() was added, but | I can't remember what that reason might have been...

[Python-Dev] Adding start to enumerate()

2008-05-11 Thread Georg Brandl
I believe the following is a common use-case for enumerate() (at least, I've used it quite some times): for lineno, line in enumerate(fileobject): ... For this, it would be nice to have a start parameter for enumerate(). The changes are minimal -- okay for 2.6? Georg -- Thus spake the

Re: [Python-Dev] Adding start to enumerate()

2008-05-11 Thread Brett Cannon
On Sun, May 11, 2008 at 3:20 PM, Georg Brandl [EMAIL PROTECTED] wrote: I believe the following is a common use-case for enumerate() (at least, I've used it quite some times): for lineno, line in enumerate(fileobject): ... For this, it would be nice to have a start parameter for

Re: [Python-Dev] Adding start to enumerate()

2008-05-11 Thread Georg Brandl
Brett Cannon schrieb: On Sun, May 11, 2008 at 3:20 PM, Georg Brandl [EMAIL PROTECTED] wrote: I believe the following is a common use-case for enumerate() (at least, I've used it quite some times): for lineno, line in enumerate(fileobject): ... For this, it would be nice to have a start

Re: [Python-Dev] Adding start to enumerate()

2008-05-11 Thread Steven D'Aprano
On Mon, 12 May 2008 08:20:51 am Georg Brandl wrote: I believe the following is a common use-case for enumerate() (at least, I've used it quite some times): for lineno, line in enumerate(fileobject): ... For this, it would be nice to have a start parameter for enumerate(). Why would it

Re: [Python-Dev] Adding start to enumerate()

2008-05-11 Thread Brett Cannon
On Sun, May 11, 2008 at 4:42 PM, Steven D'Aprano [EMAIL PROTECTED] wrote: On Mon, 12 May 2008 08:20:51 am Georg Brandl wrote: I believe the following is a common use-case for enumerate() (at least, I've used it quite some times): for lineno, line in enumerate(fileobject): ... For

Re: [Python-Dev] Adding start to enumerate()

2008-05-11 Thread Facundo Batista
2008/5/11, Brett Cannon [EMAIL PROTECTED]: It's a common enough use-case, so I think it makes sense. With the cost being so minimal to add support I think this one use-case alone is enough to justify adding the support. +1 -- .Facundo Blog: http://www.taniquetil.com.ar/plog/ PyAr:

Re: [Python-Dev] Adding start to enumerate()

2008-05-11 Thread Greg Ewing
Steven D'Aprano wrote: The only thing I can think of is printing lines with line numbers Parsing a file and wanting to be able to print error messages with line numbers would seem to be a fairly likely use. -- Greg ___ Python-Dev mailing list

Re: [Python-Dev] Adding start to enumerate()

2008-05-11 Thread Guido van Rossum
+1 to this. On Sun, May 11, 2008 at 6:23 PM, Scott Dial [EMAIL PROTECTED] wrote: Brett Cannon wrote: Taking a new argument that has a default shouldn't be an issue. +1 from me. I assume it is just going to start the count at that number, not advance the iterable to that point, right? I

Re: [Python-Dev] Adding start to enumerate()

2008-05-11 Thread Brett Cannon
On Sun, May 11, 2008 at 6:23 PM, Scott Dial [EMAIL PROTECTED] wrote: Brett Cannon wrote: Taking a new argument that has a default shouldn't be an issue. +1 from me. I assume it is just going to start the count at that number, not advance the iterable to that point, right? I wonder if it

Re: [Python-Dev] Adding start to enumerate()

2008-05-11 Thread A.M. Kuchling
On Mon, May 12, 2008 at 12:21:00PM +1200, Greg Ewing wrote: Parsing a file and wanting to be able to print error messages with line numbers would seem to be a fairly likely use. Couldn't people be using the fileinput module for this, though? --amk

Re: [Python-Dev] Adding start to enumerate()

2008-05-11 Thread Scott Dial
Brett Cannon wrote: Sure, making it 'start' or something and having it be keyword-only makes sense. http://bugs.python.org/issue2831 -Scott -- Scott Dial [EMAIL PROTECTED] [EMAIL PROTECTED] ___ Python-Dev mailing list Python-Dev@python.org