classes and __iter__

Chris Rebert clp2 at rebertia.com
Mon Jan 9 19:15:17 EST 2012


On Mon, Jan 9, 2012 at 3:30 PM, david.garvey at gmail.com
<david.garvey at 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 (which is
accessible as .__dict__), but that's to some extent an implementation
detail whose relevance here I fail to see. My point was that, as Ian
explained, your __iter__() method, as written, is horribly broken.

> It is nice... but I don't know if this is good form?

I'm confused as to why you wrote a class (particularly when its name
is an *action* rather than a noun; big red flag right there!) for your
task in the first place. I think you'd be best served by moving your
parsing code into a function and using a
http://pypi.python.org/pypi/sorteddict , which provides the
sorted-keys property you seemed to be trying to accomplish.

Also, please avoid top-posting in the future. (See
http://en.wikipedia.org/wiki/Posting_style )

Cheers,
Chris
--
http://rebertia.com



More information about the Python-list mailing list