Critique of first python code

Dan Bishop danb_83 at yahoo.com
Sun Feb 17 02:15:44 EST 2008


On Feb 8, 7:30 pm, Zack <gol... at gmail.com> wrote:
>[snip]
>
> The generators you show here are interesting, and it prodded me on how
> to add tuples but at the moment (I'm a python newbie) the generator
> seems less readable to me than the alternative. After some input from
> Scott David Daniels I changed some of the unnecessary recursion to
> while loops. I completely over thought my problem. I've fetched pylint
> and I'll be sure to keep it in my toolkit. What does everyone think of
> the code below? Are generator functions a more pythonic (preferred?)
> way of doing things or will my while loops escape mocking? Thanks for
> the feedback this has been a great exercise for me.
>
>[code example snipped]

Your functions look like good candidates for generators, but I
wouldn't mock you for using while loops.

I will say, however, that hasattr(item, '__iter__') isn't a perfect
way of checking whether an object is iterable: Objects that just
define __getitem__ are iterable too (e.g., UserList).



More information about the Python-list mailing list