I aim to create a dynamic range of a python loop. I know once the end range is computed only once, when it is passed as an argument to the range generator. However, this an example:
i = 1
for i in range(1,i,1):
print i
i = i +1
it is obvious that with i=1 the loop is skipped. But I want somehow that this range is dynamically changing according to i parameter.
This is my case where I want to use a dynamic range:
I calculate the capacity of a link
I calculate the bandwidth on that link
I do a loop with increasing of traffic sent in which should be equal to the capacity, I call it overload value.
The increasing is of range starts from 1 to the overload value.
This overload value is being calculated every time in each iteration, and it updates the range. If say theoretically the overload value is 20, then the range goes until 20.
This is my code:
capacity = Router_1.get_tunnel_capacity()
tunnel_bandwidth = Router_1.check_bandwidth_overload()
if tunnel_bandwidth <= capacity:
for bandwidth in range(1, range_end, 1):
os.system('iperf -c ' + server_address + ' -u -p 50001 -b ' + str(bandwidth) + 'M -i 1')
tunnel_bandwidth = Router_1.check_bandwidth_overload()
if tunnel_bandwidth <= capacity:
# update the range_end according to tunnel_bandwidth
range_end is the dynamic value of the range. Is there anyway to make it dynamic?