Re: [Tutor] making object iterable

2011-02-05 Thread Alex Hall
On 2/5/11, bob gailer wrote: > On 2/5/2011 2:46 PM, Alex Hall wrote: >> Hi all, >> I have a class which has a list as an attribute, meaning you must say >> something like: >> for result in obj.results: ... >> I want to make life a bit easier and let users just say: >> for result in obj: ... >> Her

Re: [Tutor] making object iterable

2011-02-05 Thread bob gailer
On 2/5/2011 2:46 PM, Alex Hall wrote: Hi all, I have a class which has a list as an attribute, meaning you must say something like: for result in obj.results: ... I want to make life a bit easier and let users just say: for result in obj: ... Here is what I have tried to make my class into an ite

Re: [Tutor] making object iterable

2011-02-05 Thread Alex Hall
On 2/5/11, Siim Märtmaa wrote: > 2011/2/5 Alex Hall : >> Yes, I get the same thing. However, when you try to index, as in a[0], >> you have problems. Here are two lines from my program: >> for i in res: print i >> This works as expected, printing every object in res.results, just as I >> wanted. >

Re: [Tutor] making object iterable

2011-02-05 Thread Siim Märtmaa
2011/2/5 Alex Hall : > Yes, I get the same thing. However, when you try to index, as in a[0], > you have problems. Here are two lines from my program: > for i in res: print i > This works as expected, printing every object in res.results, just as I > wanted. > > for i in range(len(res)): print str

Re: [Tutor] making object iterable

2011-02-05 Thread Alex Hall
On 2/5/11, Peter Otten <__pete...@web.de> wrote: > Alex Hall wrote: > >> Hi all, >> I have a class which has a list as an attribute, meaning you must say >> something like: >> for result in obj.results: ... >> I want to make life a bit easier and let users just say: >> for result in obj: ... >> Her

Re: [Tutor] making object iterable

2011-02-05 Thread James Reynolds
You should probably read this section in the python tutorial: http://docs.python.org/tutorial/classes.html#iterators If you have any questions after that, I would suggest posting back here but that should cover it. On Sat, Feb 5, 2011 at 2:46 PM, Alex Hall wrote: > Hi all, > I have a class whi

Re: [Tutor] making object iterable

2011-02-05 Thread Peter Otten
Alex Hall wrote: > Hi all, > I have a class which has a list as an attribute, meaning you must say > something like: > for result in obj.results: ... > I want to make life a bit easier and let users just say: > for result in obj: ... > Here is what I have tried to make my class into an iterable on

[Tutor] making object iterable

2011-02-05 Thread Alex Hall
Hi all, I have a class which has a list as an attribute, meaning you must say something like: for result in obj.results: ... I want to make life a bit easier and let users just say: for result in obj: ... Here is what I have tried to make my class into an iterable one, yet I get an error saying tha