簡體   English   中英

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(o/p-2),3.txt(o/)中打印從1到10的數字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是一個包含多個圖像的數組(不是物理位置)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM