我有兩種不同語言的2個文本文件,並且它們是逐行對齊的。即textfile1中的第一行應該等於textfile2中的第一行,依此類推。同時讀取兩個文本文件--python
有沒有辦法同時讀取兩個文件的文件?
下面是文件應該是什麼樣子的示例,想象一下每個文件的行數大約爲1,000,000。
textfile1:
This is a the first line in English
This is a the 2nd line in English
This is a the third line in English
textfile2:
C'est la première ligne en Français
C'est la deuxième ligne en Français
C'est la troisième ligne en Français
所需的輸出
This is a the first line in English\tC'est la première ligne en Français
This is a the 2nd line in English\tC'est la deuxième ligne en Français
This is a the third line in English\tC'est la troisième ligne en Français
有這個Read two textfile line by line simultaneously -java的Java版本,但是Python不使用的BufferedReader讀取線按行。那麼它將如何完成?
這不是Python,但如果你只需要在一個新的文件輸出,'粘貼textfile1 textfile2> output'也應該工作。 – eumiro
如果你喜歡larsmans的回答,你可能想把它標記爲已接受。 –