Re: classes and __iter__

2012-01-09 Thread david.gar...@gmail.com
Many thanks mrabarnett for the code critic... On Mon, Jan 9, 2012 at 5:08 PM, MRAB wrote: > On 09/01/2012 22:51, david.gar...@gmail.com wrote: > >> Hello, >> >> I have a class and i return both a key list and dictionary from the >> class. Is it good form to do this? The print helo.__dict__ sho

Re: classes and __iter__

2012-01-09 Thread david.gar...@gmail.com
*Here is a good tutorial: http://shutupandship.com/articles/iterators/index.html * On Mon, Jan 9, 2012 at 5:22 PM, david.gar...@gmail.com < david.gar...@gmail.com> wrote: > I see your meaning for __iter__ method.;) > > > On Mon, Jan 9, 2012 at 4:57 PM, david.gar...@gmail.com < > david.gar...@gmai

Re: classes and __iter__

2012-01-09 Thread david.gar...@gmail.com
I see your meaning for __iter__ method.;) On Mon, Jan 9, 2012 at 4:57 PM, david.gar...@gmail.com < david.gar...@gmail.com> wrote: > Thanks Ian & Chris for the conversation... > > > > > On Mon, Jan 9, 2012 at 4:15 PM, Chris Rebert wrote: > >> On Mon, Jan 9, 2012 at 3:30 PM, david.gar...@gmail.com

Re: classes and __iter__

2012-01-09 Thread MRAB
On 09/01/2012 22:51, david.gar...@gmail.com wrote: Hello, I have a class and i return both a key list and dictionary from the class. Is it good form to do this? The print helo.__dict__ shows both the list and dictionary. >>> class Parse_Nagios_Header: ... def __init__(self): ...

Re: classes and __iter__

2012-01-09 Thread david.gar...@gmail.com
Thanks Ian & Chris for the conversation... On Mon, Jan 9, 2012 at 4:15 PM, Chris Rebert wrote: > On Mon, Jan 9, 2012 at 3:30 PM, david.gar...@gmail.com > wrote: > > Chris, > > > > Both a list and dict are both iterable. I get a python dictionary > object of > > both iterables.;) > > No, you

Re: classes and __iter__

2012-01-09 Thread Chris Rebert
On Mon, Jan 9, 2012 at 3:30 PM, david.gar...@gmail.com wrote: > Chris, > > Both a list and dict are both iterable.  I get a python dictionary object of > both iterables.;) No, you get a Python object with both iterables as instance variables. Instance variables happen to be stored using a dict (w

Re: classes and __iter__

2012-01-09 Thread Ian Kelly
On Mon, Jan 9, 2012 at 4:30 PM, david.gar...@gmail.com wrote: > Chris, > > Both a list and dict are both iterable.  I get a python dictionary object of > both iterables.;) It is nice... but I don't know if this is good form? > Should I be asking the duck question here? print helo.__dict__ [SN

Re: classes and __iter__

2012-01-09 Thread david.gar...@gmail.com
Chris, Both a list and dict are both iterable. I get a python dictionary object of both iterables.;) It is nice... but I don't know if this is good form? Should I be asking the duck question here? >>> print helo.__dict__ {'keylist': [0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20,

Re: classes and __iter__

2012-01-09 Thread Ian Kelly
On Mon, Jan 9, 2012 at 3:51 PM, david.gar...@gmail.com wrote: > ... def __iter__(self): > ... return iter(self.keylist, self.d) This method is incorrect. The 2-argument form of iter() is very different from the 1-argument form. Whereas the 1-argument form takes an iterable, the 2-ar

Re: classes and __iter__

2012-01-09 Thread Chris Rebert
On Mon, Jan 9, 2012 at 2:51 PM, david.gar...@gmail.com wrote: class Parse_Nagios_Header: > ... def __init__(self): > ... self.keylist = [] > ... self.d = {} > ... def __iter__(self): > ... return iter(self.keylist, self.d) No idea what you're expecting this

classes and __iter__

2012-01-09 Thread david.gar...@gmail.com
Hello, I have a class and i return both a key list and dictionary from the class. Is it good form to do this? The print helo.__dict__ shows both the list and dictionary. >>> class Parse_Nagios_Header: ... def __init__(self): ... self.keylist = [] ... self.d = {} ...