Here is the snippet. How can I re-write this to do away with the first WHILE loop?
start = 1
end = 4
currentcount = 0
while start < end:
file = open('C:\Users\Owner\Desktop\\test' + str(start) + '.txt')
for line in file:
f = o.open('http://www.test.com/?userid=' + line.strip())
f.close()
time.sleep(10)
currentcount += 1
start += 1
Change your while loop to this:
Then use
iin the method body. Other points:startas a counter is potentially confusing. If you change the value ofstartit is no longer the start.r'C:\Users\Owner\Desktop\test'str.formatto build the string rather than string concatenation.In Python 2.x
xrangecan be slightly more efficient thanrange, although that probably isn’t a significant issue here given the size of the numbers involved.