Why loop overwriting my file instead of writing after text?

前端 未结 2 1872
星月不相逢
星月不相逢 2021-01-16 01:40
i = 1 # keep track of file number
directory = \'/some/directory/\'


for i in range(1, 5170): #number of files in directory
    filename = directory + \'D\' + str(i)         


        
2条回答
  •  遥遥无期
    2021-01-16 02:26

    Your issue is that you open in write mode. To append to file you want to use append. See here.

提交回复
热议问题