I am trying to get the following output until a certain condition is met.
test_1.jpg test_2.jpg .. test_50.jpg
The solution (if you could remotely call
Update for Python v3.6+ - using formatted string literals:
for n in range(1,51):
print(f'test_{n}')
It's probably easiest to keep dstPath something like "test_%d.jpg", and just pass it a varying count:
dstPath = "test_%d.jpg"
i = 1
while os.path.exists(dstPath % i):
i += 1
dstPath = dstPath % i # Final name
Print out the value of parts[0] each time you go round the loop ... I think you may be surprised,
It seems as though your condition os.path.exists(dstPath)
is matching the same renamed file multiple times. So for example, it renames test.jpg to test_1.jpg; then renames test_1.jpg to test_1_2.jpg, etc.
for j in range(1,10):
print("test_{0}.jpg".format(j))
enter image description here