Increment number in string

后端 未结 5 1631
孤独总比滥情好
孤独总比滥情好 2021-01-14 09:14

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

5条回答
  •  借酒劲吻你
    2021-01-14 09:25

    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
    

提交回复
热议问题