I am accessing a text file of the form
Name1
Name2
Name3
...
with the following code:
names = []
with open('./[path]/text_doc.txt', mode='r') as file:
names = file.readlines()
for name in names:
name = name.strip('\n')
print(names)
This produces the following list, and I have no idea why:
['Name1\n', 'Name2\n', 'Name3\n', ...]
I don't understand what in my code is failing to remove these trailing newline characters – names
is identical before and after the for loop, which doesn't make any sense to me as what is in the for loop should explicitly remove the newline characters from each entry in the list.