我有两种不同语言的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的回答,你可能想把它标记为已接受。 –