I have problems with the following code:
file = open(\"file.txt\", \"r\") lines = file.readlines() print lines[0] print lines[1] print lines[2] file.close()
readlines() will return an array of lines. Every line ends up with a line break.
readlines()
If you want to print all lines in a block, simply do this:
with open("file.txt", "r") as file: lines = file.readlines() print "".join(lines)
Use with, you can ever save a file.close()
with
file.close()