Re: [Python-Dev] itertools addition: getitem()

2007-07-08 Thread Guido van Rossum
On 7/9/07, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > Also, as a practical matter, I think it is a bad idea to introduce > __getitem__ style access to itertools because the starting point > moves with each consecutive access: > > # access items 0, 2, 5, 9, 14, 20, ... > for i in range(1

Re: [Python-Dev] itertools addition: getitem()

2007-07-08 Thread Walter Dörwald
Raymond Hettinger wrote: > [Walter Dörwald] >> I'd like to propose the following addition to itertools: A function >> itertools.getitem() which is basically equivalent to the following >> python code: >> >> _default = object() >> >> def getitem(iterable, index, default=_default): >>try: >>

Re: [Python-Dev] itertools addition: getitem()

2007-07-08 Thread Raymond Hettinger
[Walter Dörwald] > I'd like to propose the following addition to itertools: A function > itertools.getitem() which is basically equivalent to the following > python code: > > _default = object() > > def getitem(iterable, index, default=_default): >try: > return list(iterable)[index] >

Re: [Python-Dev] itertools addition: getitem()

2007-07-08 Thread Walter Dörwald
Guido van Rossum wrote: > On 7/8/07, Walter Dörwald <[EMAIL PROTECTED]> wrote: > [quoting Guido] >> > But I still want to hear of a practical use case for the default here. >> >> In most cases >> >> foo = getitem(iterable, 0, None) >> if foo is not None: >>... >> >> is simpler than

Re: [Python-Dev] Summary of Tracker Issues

2007-07-08 Thread Steve Holden
Brett Cannon wrote: > On 7/7/07, Josiah Carlson <[EMAIL PROTECTED]> wrote: >> Steve Holden <[EMAIL PROTECTED]> wrote: >>> Tracker wrote: ACTIVITY SUMMARY (07/01/07 - 07/08/07) Tracker at http://bugs.python.org/ To view or respond to any of the issues listed b

Re: [Python-Dev] PEP 366 - Relative imports from main modules

2007-07-08 Thread Brett Cannon
On 7/8/07, Nick Coghlan <[EMAIL PROTECTED]> wrote: > Josiah Carlson wrote: > > "Brett Cannon" <[EMAIL PROTECTED]> wrote: > >> On 7/5/07, Phillip J. Eby <[EMAIL PROTECTED]> wrote: > >>> At 11:53 AM 7/5/2007 +0200, Guido van Rossum wrote: > I see no big problems with this, except I wonder if in

Re: [Python-Dev] Summary of Tracker Issues

2007-07-08 Thread Brett Cannon
On 7/7/07, Josiah Carlson <[EMAIL PROTECTED]> wrote: > > Steve Holden <[EMAIL PROTECTED]> wrote: > > Tracker wrote: > > > > > > ACTIVITY SUMMARY (07/01/07 - 07/08/07) > > > > > > > > > Tracker at http://bugs.python.org/ > > > > > > To view or respond to any of the issues listed below, sim

Re: [Python-Dev] proposed attribute lookup optimization

2007-07-08 Thread Phillip J. Eby
At 08:23 PM 7/8/2007 +0300, Paul Pogonyshev wrote: >I would like to propose an optimization (I think so, anyway) for the >way attributes are looked up. Currently, it is done like this: > > return value of attribute in instance.__dict__ if present > for type in instance.__class__.__

[Python-Dev] proposed attribute lookup optimization

2007-07-08 Thread Paul Pogonyshev
Hi, I would like to propose an optimization (I think so, anyway) for the way attributes are looked up. Currently, it is done like this: return value of attribute in instance.__dict__ if present for type in instance.__class__.__mro__: return value of attribute in type.

Re: [Python-Dev] itertools addition: getitem()

2007-07-08 Thread Steven Bethard
On 7/8/07, Kevin Jacobs <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> wrote: > Also vaguely apropos: > > def ilen(seq): > 'Return the length of the hopefully finite sequence' > n = 0 > for x in seq: > n += 1 > return n Also known as:: sum(1 for _ in iterable) That's always been simple

Re: [Python-Dev] itertools addition: getitem()

2007-07-08 Thread Kevin Jacobs <[EMAIL PROTECTED]>
On 7/8/07, Guido van Rossum <[EMAIL PROTECTED]> wrote: Ahem. I hope you have a better use case for getitem() than that (regardless of the default issue). I find it clearer to write that as try: compid = root[ns.company_id].next() except StopIteration: compid = None else: compid = int(comp

Re: [Python-Dev] itertools addition: getitem()

2007-07-08 Thread Guido van Rossum
On 7/8/07, Walter Dörwald <[EMAIL PROTECTED]> wrote: [quoting Guido] > > But I still want to hear of a practical use case for the default here. > > In most cases > > foo = getitem(iterable, 0, None) > if foo is not None: >... > > is simpler than: > > try: >foo = getitem(

Re: [Python-Dev] itertools addition: getitem()

2007-07-08 Thread Walter Dörwald
Guido van Rossum wrote: > On 7/8/07, Georg Brandl <[EMAIL PROTECTED]> wrote: >> Guido van Rossum schrieb: >>> How important is it to have the default in this API? __getitem__() >>> doesn't have a default; instead, there's a separate API get() that >>> provides a default (and I find defaulting to No

Re: [Python-Dev] itertools addition: getitem()

2007-07-08 Thread Guido van Rossum
On 7/8/07, Georg Brandl <[EMAIL PROTECTED]> wrote: > Guido van Rossum schrieb: > > How important is it to have the default in this API? __getitem__() > > doesn't have a default; instead, there's a separate API get() that > > provides a default (and I find defaulting to None more manageable than > >

Re: [Python-Dev] itertools addition: getitem()

2007-07-08 Thread Georg Brandl
Guido van Rossum schrieb: > How important is it to have the default in this API? __getitem__() > doesn't have a default; instead, there's a separate API get() that > provides a default (and I find defaulting to None more manageable than > the "_default = object()" pattern). getattr() has a default

Re: [Python-Dev] itertools addition: getitem()

2007-07-08 Thread Guido van Rossum
How important is it to have the default in this API? __getitem__() doesn't have a default; instead, there's a separate API get() that provides a default (and I find defaulting to None more manageable than the "_default = object()" pattern). --Guido On 7/8/07, Walter Dörwald <[EMAIL PROTECTED]> wr

Re: [Python-Dev] Python for embedding?

2007-07-08 Thread Martin v. Löwis
> What is my idea, is to make a Python implementation made to be embedded > into applications.. > > Hope you have any ideas/comments! My main question: Who will implement that idea? Ideas are cheap; making them come true is a lot of work. It seems that you believe the current implementation of

[Python-Dev] itertools addition: getitem()

2007-07-08 Thread Walter Dörwald
I'd like to propose the following addition to itertools: A function itertools.getitem() which is basically equivalent to the following python code: _default = object() def getitem(iterable, index, default=_default): try: return list(iterable)[index] except IndexError: if d

Re: [Python-Dev] PEP 366 - Relative imports from main modules

2007-07-08 Thread Nick Coghlan
Josiah Carlson wrote: > "Brett Cannon" <[EMAIL PROTECTED]> wrote: >> On 7/5/07, Phillip J. Eby <[EMAIL PROTECTED]> wrote: >>> At 11:53 AM 7/5/2007 +0200, Guido van Rossum wrote: I see no big problems with this, except I wonder if in the end it wouldn't be better to *always* define __packa