Re: classes and __iter__

2012-01-09 Thread [email protected]
Many thanks mrabarnett for the code critic... On Mon, Jan 9, 2012 at 5:08 PM, MRAB wrote: > On 09/01/2012 22:51, [email protected] 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 [email protected]
*Here is a good tutorial: http://shutupandship.com/articles/iterators/index.html * On Mon, Jan 9, 2012 at 5:22 PM, [email protected] < [email protected]> wrote: > I see your meaning for __iter__ method.;) > > > On Mon, Jan 9, 2012 at 4:57 PM, [email protected] < > david.gar...@gmai

Re: classes and __iter__

2012-01-09 Thread [email protected]
I see your meaning for __iter__ method.;) On Mon, Jan 9, 2012 at 4:57 PM, [email protected] < [email protected]> 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, [email protected]

Re: classes and __iter__

2012-01-09 Thread MRAB
On 09/01/2012 22:51, [email protected] 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 [email protected]
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, [email protected] > 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, [email protected] 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, [email protected] 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 [email protected]
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, [email protected] 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, [email protected] 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 [email protected]
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 = {} ...