Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18723
| References | <CA+oqfxRF4Gm=hfWsHRZ0mG-v=QSuNS+ED72x+d2b-5CO6BnaqQ@mail.gmail.com> <CAMZYqRRmKxrp7v_9OKpNjjO-RSWovQ0o91Y4SkN55c4hjiw4uw@mail.gmail.com> <CA+oqfxSwaYd=84-Ykkp3dTzJgDoioWAWLDU1Ow0LmisZYjgp4A@mail.gmail.com> |
|---|---|
| Date | 2012-01-09 16:15 -0800 |
| Subject | Re: classes and __iter__ |
| From | Chris Rebert <clp2@rebertia.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4562.1326154520.27778.python-list@python.org> (permalink) |
On Mon, Jan 9, 2012 at 3:30 PM, david.garvey@gmail.com <david.garvey@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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: classes and __iter__ Chris Rebert <clp2@rebertia.com> - 2012-01-09 16:15 -0800
csiph-web