# open the sample file used file = open('logFile.txt') # read the content of the file opened content = file.readlines() print(content[287:330]) #need to print separate line for 287 line to 330.
我期待单独的线路。 请帮助我。
这里有几种不同的方法,都可以利用此代码片段来读取文件的内容:
with open('logFile.txt') as file: content = file.readlines()
end
函数的
print
for line in content[287:330]: print(line, end='')
str.join
print('\n'.join(content[287:330]))
*
sep
print(*content[287:330], sep='\n')