Re:Python Best Practice Patterns
by mercurial on Friday February 28, 2014 @02:24PM
(#7320878)
The whole "use __iter__ whenever you can" thing is dubious too. It may be fine sometimes but the example is poorly chosen. If the department gains a name and a manager, using __iter__ makes much less sense. And now you also need to implement __len__ if you want to count your employees, etc.
[ Parent
| on HN ]
Re:Python Best Practice Patterns
by IgorPartola on Friday February 28, 2014 @04:49PM
(#7321744)
And possibly allow indexing: `department[3]`. Yeah, I don't like that. It's not clear whether it's a generator or a full sequence. Generators when you don't expect them are evil (you cannot iterate over them twice). I would much rather see something like department.get_employees() and department.iget_employees() that return a tuple and a generator respectively.