Opening a file in "w" mode creates it or replaces its contents. file.write(text) writes exactly the characters in its argument.
A scoreboard builds a line with two writes. Opening it again reveals which characters actually reached the file.
with open("score.txt", "w", encoding="utf-8") as board:
board.write("Red")
board.write(" 4\n")
with open("score.txt", encoding="utf-8") as board:
print(repr(board.read())) # 'Red 4\n'A call to write does not add a separator. Supply the line ending exactly where a record finishes.
Implement write_guests(path, names). Replace the UTF-8 file with the names in arrival order, one per line. End every name with a newline. An empty list should leave an empty file.
write_guests("door.txt", ["Noor", "René"])
# door.txt now contains "Noor\nRené\n"