[RFC] checkpatch.py

Greg Ward greg-hg at gerg.ca
Sat Jul 4 18:08:20 CDT 2009


On Sat, Jul 4, 2009 at 5:36 AM, Martin Geisler<mg at lazybytes.net> wrote:
> The built-in enumerate function takes a sequence and add indices to it:
>
>    >>> list(enumerate(["foo", "bar", "baz"]))
>    [(0, 'foo'), (1, 'bar'), (2, 'baz')]
>
> You use it like this:
>
>  for count, line in enumerate(lines):
>      # ...

Careful: if 'lines' is actually a file object, this will suck the
entire file into memory and return a big list.  (At least in Python
2.x: has enumerate() has been turned into an iterable in Py3k?)  There
is still room for the "count += 1" idiom.

Greg



More information about the Mercurial-devel mailing list