1with open("test.txt") as f:
2 lines = f.readlines()
3
4lines # ['This is the first line.\n', 'This is the second line.\n']
5
6lines[0] = "This is the line that's replaced.\n"
7
8lines # ["This is the line that's replaced.\n", 'This is the second line.\n']
9
10with open("test.txt", "w") as f:
11 f.writelines(lines)