Re: [Tutor] iter class

2014-01-23 Thread eryksun
On Thu, Jan 23, 2014 at 7:43 PM, Steven D'Aprano wrote: > Generators are a kind of function, which are special. You can't inherit > from them: I clarified my sloppy language in a reply. `__iter__` should be a generator function, not a generator. A generator function uses `yield` and `yield from`

Re: [Tutor] iter class

2014-01-23 Thread Steven D'Aprano
On Thu, Jan 23, 2014 at 02:24:20PM -0500, Keith Winston wrote: > On Thu, Jan 23, 2014 at 7:05 AM, eryksun wrote: > > Generally you'll make `__iter__` a generator, so you don't have to > > worry about implementing `__next__`. Also, the built-in function > > `next` was added in 2.6, so you don't hav

Re: [Tutor] iter class

2014-01-23 Thread Steven D'Aprano
On Thu, Jan 23, 2014 at 02:18:33PM -0500, Keith Winston wrote: > On Thu, Jan 23, 2014 at 1:36 PM, Devin Jeanpierre > wrote: > > > Again, nothing was incorrect about the example. Every iterator has > > this "problem". > > Hmmm. Well, here's what he actually said about that example, since I > don'

Re: [Tutor] iter class

2014-01-23 Thread eryksun
On Thu, Jan 23, 2014 at 2:24 PM, Keith Winston wrote: > On Thu, Jan 23, 2014 at 7:05 AM, eryksun wrote: >> Generally you'll make `__iter__` a generator, so you don't have to >> worry about implementing `__next__`. Also, the built-in function >> `next` was added in 2.6, so you don't have to worry

Re: [Tutor] iter class

2014-01-23 Thread Keith Winston
On Thu, Jan 23, 2014 at 7:05 AM, eryksun wrote: > Generally you'll make `__iter__` a generator, so you don't have to > worry about implementing `__next__`. Also, the built-in function > `next` was added in 2.6, so you don't have to worry about the method > name difference between 2.x and 3.x, eith

Re: [Tutor] iter class

2014-01-23 Thread Keith Winston
On Thu, Jan 23, 2014 at 1:36 PM, Devin Jeanpierre wrote: > Again, nothing was incorrect about the example. Every iterator has > this "problem". Hmmm. Well, here's what he actually said about that example, since I don't think I've explained correctly: * With iterators, one thing to watch out

Re: [Tutor] iter class

2014-01-23 Thread Devin Jeanpierre
On Thu, Jan 23, 2014 at 7:50 AM, Keith Winston wrote: > Yes, the exercise was about implementing an iter incorrectly, to see > the difference. But I don't really understand your second point: when > I changed the method name, it worked...? Again, nothing was incorrect about the example. Every ite

Re: [Tutor] iter class

2014-01-23 Thread eryksun
On Thu, Jan 23, 2014 at 10:50 AM, Keith Winston wrote: > On Thu, Jan 23, 2014 at 7:05 AM, eryksun wrote: >> Generally you'll make `__iter__` a generator, so you don't have to >> worry about implementing `__next__`. Also, the built-in function >> `next` was added in 2.6, so you don't have to worry

Re: [Tutor] iter class

2014-01-23 Thread Keith Winston
On Thu, Jan 23, 2014 at 7:05 AM, eryksun wrote: > Generally you'll make `__iter__` a generator, so you don't have to > worry about implementing `__next__`. Also, the built-in function > `next` was added in 2.6, so you don't have to worry about the method > name difference between 2.x and 3.x, eith

Re: [Tutor] iter class

2014-01-23 Thread Keith Winston
On Thu, Jan 23, 2014 at 3:09 AM, Peter Otten <__pete...@web.de> wrote: > But why not install Python 2.7 on your machine, too? That would allow you > run the examples as is. Y'know, it's funny, but I have 2.7 installed. But since I was almost certain it was a 2to3 kind of problem, I wanted to figur

Re: [Tutor] iter class

2014-01-23 Thread Keith Winston
On Thu, Jan 23, 2014 at 5:56 AM, spir wrote: > Yes, but that way others learn as well :-) And many people prefere learning > via human interaction then dealing with arid texts Well, you caught me. I do run out of steam just plowing through lessons & such: it really helps to have actual humans to

Re: [Tutor] iter class

2014-01-23 Thread eryksun
On Thu, Jan 23, 2014 at 12:53 AM, Keith Winston wrote: >> in Python 3, it should be __next__, not next. > > Ah! That's it! Thanks!!! Generally you'll make `__iter__` a generator, so you don't have to worry about implementing `__next__`. Also, the built-in function `next` was added in 2.6, so you

Re: [Tutor] iter class

2014-01-23 Thread spir
On 01/23/2014 06:53 AM, Keith Winston wrote: I suppose I should practice running my questions on old code through 2to3 before I pester the Tutor list, since that's probably also a good way to learn the differences. Yes, but that way others learn as well :-) And many people prefere learning via

Re: [Tutor] iter class

2014-01-23 Thread Peter Otten
Keith Winston wrote: > On Thu, Jan 23, 2014 at 12:21 AM, Devin Jeanpierre > wrote: >> in Python 3, it should be __next__, not next. > > Ah! That's it! Thanks!!! > >> I'd suggest staying away from any old blog posts and articles, unless >> you'd care to learn Python 2.x instead of 3.x. ;) > > Y

Re: [Tutor] iter class

2014-01-22 Thread Keith Winston
On Thu, Jan 23, 2014 at 12:21 AM, Devin Jeanpierre wrote: > in Python 3, it should be __next__, not next. Ah! That's it! Thanks!!! > I'd suggest staying away from any old blog posts and articles, unless > you'd care to learn Python 2.x instead of 3.x. ;) Yeah, but this is a REALLY GOOD resource

Re: [Tutor] iter class

2014-01-22 Thread Devin Jeanpierre
On Wed, Jan 22, 2014 at 8:57 PM, Keith Winston wrote: > I'm working my way through some of the examples in > > http://ivory.idyll.org/articles/advanced-swc/#list-comprehensions > > And tried this one: > class MyTrickyIter: > ... def __init__(self, thelist): > ... self.thelist = thelist

[Tutor] iter class

2014-01-22 Thread Keith Winston
I'm working my way through some of the examples in http://ivory.idyll.org/articles/advanced-swc/#list-comprehensions And tried this one: >>> class MyTrickyIter: ... def __init__(self, thelist): ... self.thelist = thelist ... self.index = -1 ... ... def __iter__(self): ... retu