如何在 python 中显示多个文本文件的输出,例如:在 1.txt、2.txt、3.txt 中打印从 1 到 10 的数字

How to show the output in multiple text files in python, for example: print digits from 1 to 10 in 1.txt,2.txt,3.txt

如何在python中显示多个文本文件的输出,例如:在1.txt(o/p-1),2.txt(中打印从1到10的数字o/p-2),3.txt(o/p-3) 个文件... 这是我试过的一段代码,将图像文件作为文本获取并将其存储在单独的文件夹中。

     c=-1

     outFile=[] //created a list,as it would overwrite the same outfile multiple times if not used(expecting it to be a different file when list is used)


     for i in range(0, len(onlyfiles)):
                

   `     
         text = pytesseract.image_to_string(images[i])

         c=c+1

         outFile.append(c)

         outFile[c] = open(str1+"outputfile.txt", "w")//str values could be incremented using a different loop/function to have difference in name.
  
         outFile[c].write(text)

         outFile[c].close()

非常感谢任何修改或新方法。

for i in images:
    text = pytesseract.image_to_string(i)
    with open(f"{i}.txt", w) as f:
        f.write(text)

假设:

  1. 我们将在当前目录中保存文本文件(1.txt、2.txt、....)。
  2. images 是一个包含多张图片(不是物理位置)的数组