Recursive list comprehension
Steven Bethard
steven.bethard at gmail.com
Wed Dec 8 22:59:39 EST 2004
Terry Reedy wrote:
> This is a ways off, if ever, but I think the general advice for user code
> is to use the newer protocol.
Yes, definitely. I hope no one misconstrued me to be suggesting that
you should use the 'sequence protocol' for iterators (e.g. using
__getitem__ and raising an IndexError). This is deprecated and is only
supported for backwards compatiblity. All new code should define
__iter__ instead.
> So, for the purpose of writing new code, I
> think it justified to forget about or at least ignore the older iteration
> protocol.
This is probably valid as long as you don't need your code to work with
any objects defined before the __iter__ protocol.
Steve
More information about the Python-list
mailing list