Opening a file with with open(path, encoding="utf-8") as file: gives you a file object. Its read() method returns the entire text, including line endings.
Read one line from a temporary file and inspect the characters that Python returns.
with open("platform.txt", "w", encoding="utf-8") as file:
file.write("Platform 2\nDepart at 10\n")
with open("platform.txt", encoding="utf-8") as file:
first = file.readline()
print(repr(first)) # 'Platform 2\n'The line ending is part of the text. Reading the whole file should preserve the second line as well.
Implement read_notice(path). Return the exact contents of the supplied UTF-8 file. Keep spaces, blank lines, and the final newline if there is one.
with open("board.txt", "w", encoding="utf-8") as board:
board.write("Café closes at five.\n")
print(repr(read_notice("board.txt"))) # 'Café closes at five.\n'