open
file_handle = open("myfile.txt") contents = file_handle.read() print(contents)
file_handle = open("myfile.txt") contents = file_handle.read() file_handle.close() print(contents)
file_handle = open("myfile.txt") file_handle.close() contents = file_handle.read() # Raises Exception
\n
print("Line 1\nLine 2")
readline
readlines
handle = open("example.py") first_line = handle.readline() print(first_line)
handle = open("example.py") for line in handle: print(line, end='')
handle = open("myfile.txt") total = 0 for line in handle: total += int(line) print(total)
read