I have a names.txt file that is a list of names, each name is on a new line:
'Fred',
'Ed',
'George'
I want to open my txt file, extract the names and add it to a list with nice looking formatting. When I try
list=[]
names = open(names.txt)
for s in names:
display(s)
list.append(s)
The output looks like the below
" 'Fred',/n"
" 'Ed',/n"
" 'George',/n"
Naturally I get a list, but I want my list to be list = ['Fred','Ed','George']
not with the /n
, ""
and extra spaces. Does anyone know the best way to get rid of the extra white space and the /n line. I could take 2-3 steps to replace everything, but does anyone know if there is a better way?