I have code like this:
loopcount = 3
for i in range(1, loopcount)
somestring = \'7\'
newcount = int(somestring)
loopcount = newcount
Here is a more complete implementation of the adjustable_range
function provided by Joel Cornett.
def adjustable_range(start, stop=None, step=None):
if not isinstance(start, int):
raise TypeError('start')
if stop is None:
start, stop = 0, start
elif not isinstance(stop, int):
raise TypeError('stop')
direction = stop - start
positive, negative = direction > 0, direction < 0
if step is None:
step = +1 if positive else -1
else:
if not isinstance(step, int):
raise TypeError('step')
if positive and step < 0 or negative and step > 0:
raise ValueError('step')
if direction:
valid = (lambda a, b: a < b) if positive else (lambda a, b: a > b)
while valid(start, stop):
message = yield start
if message is not None:
if not isinstance(message, int):
raise ValueError('message')
stop = message
start += step