[Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Jim Fulton
Looking over some of the messages in the archives, I saw a reference to making dict keys, items, and values methods return iterators. I've heard Guido mention this in the past. I'd like to offer a word of caution here. ZODB has a BTree implemention that uses iterators for keys, values, and item

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Ian Bicking
Jim Fulton wrote: > Looking over some of the messages in the archives, I saw a reference > to making dict keys, items, and values methods return iterators. I've heard > Guido mention this in the past. I saw this too in the archives, and thought shit, that's going to mess up a lot of my code. I

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Jeremy Hylton
On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > One idea I had after reading a post of Brett's was a dual-use attribute; > if you do d.keys you get an iterable (not an iterator, of course), and > if you call that iterable you get a list. This is backward compatible, > arguably prettier anyway

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Guido van Rossum
On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > Jim Fulton wrote: > > Looking over some of the messages in the archives, I saw a reference > > to making dict keys, items, and values methods return iterators. I've heard > > Guido mention this in the past. It's been one of the first things I'v

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Jim Fulton
Guido van Rossum wrote: ... > I've read and re-read Jim's message, and I'm not sure I understand it. > It seems he's working in an interactive session Yup > but I'm not sure I > understand the problem he has with adding list() around an expression It's a hassle. > (unless he hasn't got readlin

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Barry Warsaw
On Thu, 2006-03-23 at 14:52 -0500, Jim Fulton wrote: > If we are dead set on making these methods return iterators, I'd really like > to see a way to either get non-iterators by calling a method or see some > new facilities in the iterators returned. Perhaps these iterators > could have a method

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread skip
Guido> It's interesting to me because there's a bunch of APIs that Guido> currently have two versions: one to get a list and one to get an Guido> iterator. It would be cleaner if only the iterator version Guido> existed, and the way to get a list was to put an explicit list() G

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Alex Martelli
On 3/23/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: ... > Agreed. I think there's also a perceived performance difference, whether > one exists or not. I'd be real surprised if > > for key, val in somedict.iteritems(): > blah(key, val) > > was faster than > > for key, val

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Guido van Rossum
On 3/23/06, Jim Fulton <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > ... > > I've read and re-read Jim's message, and I'm not sure I understand it. > > It seems he's working in an interactive session > > Yup Feedback taken. But I don't want to design the feature or base its user testing e

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Robert Brewer
Guido van Rossum: > > I've read and re-read Jim's message, and I'm not > > sure I understand it. It seems he's working in > > an interactive session but I'm not sure I > > understand the problem he has with adding list() > > around an expression Jim Fulton wrote: > It's a hassle. > ... > I'd be in

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Guido van Rossum
On 3/23/06, Robert Brewer <[EMAIL PROTECTED]> wrote: > It is a hassle. I recently changed my ORM's API from returning iterators > to lists based on similar user feedback (and I could have sworn I > already made this comment on this issue, but I can't find it now). That > experience hints to me that

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Ian Bicking
Robert Brewer wrote: > Guido van Rossum: > >>>I've read and re-read Jim's message, and I'm not >>>sure I understand it. It seems he's working in >>>an interactive session but I'm not sure I >>>understand the problem he has with adding list() >>>around an expression > > > Jim Fulton wrote: > >>I

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Guido van Rossum
On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > This has been my personal experience with the iterators in SQLObject as > well. The fact that an empty iterator is true tends to cause particular > problems in that case, though I notice iterkeys() acts properly in this > case; maybe part of the

[Python-3000] Backward compatibility

2006-03-23 Thread Ian Bicking
Guido van Rossum wrote: >>I saw this too in the archives, and thought shit, that's going to mess >>up a lot of my code. I would assume (though it's a separate point of >>discussion) that Python 3k should still try hard to keep backward >>compatibility. Backward compatibility isn't a requirement,

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Ian Bicking
Guido van Rossum wrote: > On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > >>This has been my personal experience with the iterators in SQLObject as >>well. The fact that an empty iterator is true tends to cause particular >>problems in that case, though I notice iterkeys() acts properly in t

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Guido van Rossum
On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > > > >>This has been my personal experience with the iterators in SQLObject as > >>well. The fact that an empty iterator is true tends to cause particular > >>proble

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Ian Bicking
Guido van Rossum wrote: > On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > >>Guido van Rossum wrote: >> >>>On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: >>> >>> This has been my personal experience with the iterators in SQLObject as well. The fact that an empty iterator is true t

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Guido van Rossum
On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: [Guido] > > Testing whether an iterator is empty or not is an oxymoron; the only > > legit way is to call next() and see whether it raises StopIteration. > > This is the fundamental confusion I am talking about. It is NOT > > "natural enough". It r

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Ian Bicking
Guido van Rossum wrote: > On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > [Guido] > >>>Testing whether an iterator is empty or not is an oxymoron; the only >>>legit way is to call next() and see whether it raises StopIteration. >>>This is the fundamental confusion I am talking about. It is NO

Re: [Python-3000] Backward compatibility

2006-03-23 Thread Brett Cannon
On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > >>I saw this too in the archives, and thought shit, that's going to mess > >>up a lot of my code. I would assume (though it's a separate point of > >>discussion) that Python 3k should still try hard to keep backward > >

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Ian Bicking
Ian Bicking wrote: > Coming back around to the idea of implementing __getitem__ and such, I > suppose a list-like iterator wrapper could be useful. That would > consume and retain the results of the iterator lazily to satisfy the > things done to the object. That would be kind of interesting;

Re: [Python-3000] Backward compatibility

2006-03-23 Thread Barry Warsaw
On Thu, 2006-03-23 at 16:02 -0800, Brett Cannon wrote: > I don't think things are going to be broken gratuitously. However, I hope we don't throw out clearly beneficial improvements for backward compatibility's sake. But yes, all things being equal, if it comes down to a tie-breaker then backwar

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Guido van Rossum
On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > > [Guido] > >>>Testing whether an iterator is empty or not is an oxymoron; the only > >>>legit way is to call next() and see whether it raises StopIteration. > >>>Th

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Brett Cannon
On 3/23/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > [Guido] > > > Testing whether an iterator is empty or not is an oxymoron; the only > > > legit way is to call next() and see whether it raises StopIteration. > > > This is the fundamental

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Brett Cannon
On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: [SNIP] > I'm testing if it is empty or not, which seems natural enough. Or would > be, if it worked. So I start out doing: > >for item in select_results: ... > >

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Ian Bicking
Guido van Rossum wrote: >>In SQLObject it came about due to a desire to lazily load objects out of >>a query. The lazy behavior had other problems (mostly introducing >>concurrency where you wouldn't expect). In addition, the query is only >>run when you start iterating. I'm not sure if that is

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Guido van Rossum
On 3/23/06, Brett Cannon <[EMAIL PROTECTED]> wrote: > On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > > When I was just > > first learning Python I thought this would work: > > > >for item in select_results: > >... > >else: > >... stuff when there are no items ... > > >

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Guido van Rossum
On 3/23/06, Brett Cannon <[EMAIL PROTECTED]> wrote: > I think there is a fundamental difference between your views of > iterators. It sounds like Ian is viewing them as a separate object; > something that happens to have derived its values from a dict in the > situation begin discussed. While it

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Ian Bicking
Guido van Rossum wrote: > But this is only needed if *all you have* is the iterator. Most of the > time, the code containing the for loop has access to the container, > and the iterator is only instantiated by the __iter__() call implied > by the for loop. I don't think that is the case. For inst

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Guido van Rossum
On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > Empty iterator or iterator that produced no items -- from the outside > it's the same use case. I see it as an education issue. Because we have generators, the iterator protocol can't be extended to support a test for emptiness -- that's just no

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Brett Cannon
On 3/23/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On 3/23/06, Brett Cannon <[EMAIL PROTECTED]> wrote: > > On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > > > When I was just > > > first learning Python I thought this would work: > > > > > >for item in select_results: > > >.

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Guido van Rossum
On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > But this is only needed if *all you have* is the iterator. Most of the > > time, the code containing the for loop has access to the container, > > and the iterator is only instantiated by the __iter__() call implied >

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Brett Cannon
On 3/23/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On 3/23/06, Brett Cannon <[EMAIL PROTECTED]> wrote: > > I think there is a fundamental difference between your views of > > iterators. It sounds like Ian is viewing them as a separate object; > > something that happens to have derived its v

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Robert Brewer
Guido van Rossum wrote: > On 3/23/06, Robert Brewer <[EMAIL PROTECTED]> wrote: > > It is a hassle. I recently changed my ORM's API from > > returning iterators to lists based on similar user > > feedback (and I could have sworn I already made > > this comment on this issue, but I can't find it > >

[Python-3000] else-clause on for-loops

2006-03-23 Thread Steven Bethard
On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > When I was just first learning Python I thought this would work: > >for item in select_results: >... >else: >... stuff when there are no items ... > > But it doesn't work like that. On 3/23/06, Brett Cannon <[EMAIL PROTEC

[Python-3000] Best Practices essays

2006-03-23 Thread Edward C. Jones
"Brett Cannon" <[EMAIL PROTECTED]> wrote: > Right. I am really starting to think that having a group of Best > Practices essays that discuss common Python idioms might be handy. > Part tutorial, part advanced usage, they would provide a way for > people to have a place to go to find out expec

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Delaney, Timothy (Tim)
Jeremy Hylton wrote: > On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: >> One idea I had after reading a post of Brett's was a dual-use >> attribute; if you do d.keys you get an iterable (not an iterator, of >> course), and if you call that iterable you get a list. This is >> backward compatib

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Ian Bicking
Guido van Rossum wrote: > On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: >> Guido van Rossum wrote: >>> But this is only needed if *all you have* is the iterator. Most of the >>> time, the code containing the for loop has access to the container, >>> and the iterator is only instantiated by the

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Guido van Rossum
On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: [...] > To me that feels like a big transformation, where I would prefer to just > be able to use "non_empty_lines(lines)" in place of "lines" and > everything would work perfectly. Well wishing ain't going to make it so. I'm not sure what you're

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Guido van Rossum
On 3/23/06, Delaney, Timothy (Tim) <[EMAIL PROTECTED]> wrote: > This whole discussion suggests to me that what would be best is if we > defined an actual "view" protocol, and various builtins return views, > rather than either copies or iterators. Right. > A view provides the same access methods,

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Jack Diederich
On Thu, Mar 23, 2006 at 05:27:48PM -0800, Guido van Rossum wrote: > On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > > Empty iterator or iterator that produced no items -- from the outside > > it's the same use case. > > I see it as an education issue. Because we have generators, the > iterato

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Adam DePrince
On Fri, 2006-03-24 at 13:15 +1100, Delaney, Timothy (Tim) wrote: > Jeremy Hylton wrote: > > > On 3/23/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > >> One idea I had after reading a post of Brett's was a dual-use > >> attribute; if you do d.keys you get an iterable (not an iterator, of > >> course)

Re: [Python-3000] Iterators for dict keys, values, and items == annoying :)

2006-03-23 Thread Aahz
On Thu, Mar 23, 2006, Guido van Rossum wrote: > On 3/23/06, Brett Cannon <[EMAIL PROTECTED]> wrote: >> >> I understand Ian's view since I know I like to pass around iterators >> for use and that disconnects the iterator from the object that >> generated it and thus makes it impossible to find out

Re: [Python-3000] Best Practices essays

2006-03-23 Thread Adam DePrince
On Thu, 2006-03-23 at 21:05 -0500, Edward C. Jones wrote: > "Brett Cannon" <[EMAIL PROTECTED]> wrote: > > > Right. I am really starting to think that having a group of Best > > Practices essays that discuss common Python idioms might be handy. > > Part tutorial, part advanced usage, they would

Re: [Python-3000] C style guide

2006-03-23 Thread Greg Ewing
Guido van Rossum wrote: > That won't go away for me (Google's settings default to TWO-space > indents :-( ) but I agree with the 4-space indent -- eventually. If we standardised on all-tabs, people could set their editors to display indentation however they wanted, and there would be no need to a