'Python alternative to using incremental counter?
Consider the following code (It doesn't really matter what it's used for):
def zipstreams(filename):
"""Return all zip streams and their positions in file."""
with open(filename, "rb") as fh:
data = fh.read()
i = 0
while i < len(data):
try:
zo = zlib.decompressobj()
yield i, zo.decompress(data[i:])
i += len(data[i:]) - len(zo.unused_data)
except zlib.error:
i += 1
Is there a better way to do something like this without using the incremental counter 0? I'm going for compactness, and I was wondering if there's a better way to do this sort of thing, so I don't have to use a counter.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
