我需要有关如何将 txt 文件中的多行连接成没有空格的单行的帮助
文本文件由 8 行组成,每行 80 个字符,如图所示:
(来源:gulfup.com)
这是我使用的代码,但我的问题是我无法将所有行连接起来,它们之间没有空格:
inFile = open ("text.txt","r") # open the text file
line1 = inFile.readline() # read the first line from the text.txt file
line2 = inFile.readline() # read the second line from the text.txt file
line3 = inFile.readline()
line4 = inFile.readline()
line5 = inFile.readline()
line6 = inFile.readline()
line7 = inFile.readline()
line8 = inFile.readline()
print (line1.split("\n")[0], # split each line and print it --- My proplem in this code!
line2.split("\n")[0],
line3.split("\n")[0],
line4.split("\n")[0],
line5.split("\n")[0],
line6.split("\n")[0],
line7.split("\n")[0],
line8.split("\n")[0])
(来源:gulfup.com)