I'm creating a list from an e-mail body and the output list contains thousands of '\n'
and '\t'
characters. I would like to know how to remove them from a Python list.
NOTE: I'm expecting to remove only the items that have no other values, since there are some index in the list that contains valuable information and special characters at the end I don't want to remove them. For example: [..., '\n', 'WDO\n', '\t\t\n', ...]
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetFirst()
for msg in messages:
subject = msg.Subject
if (subject.find('ABCDEFG') != -1):
assunto = subject
conteudo = msg.body
File_object = open(r"C:\Projetos\E-mail\body.txt","w")
File_object.write(msg.body)
File_object.close()
break
File_object = open(r"C:\Projetos\E-mail\body.txt","r")
lista = File_object.readlines()
And this is the output of the list:
lista[0:16]
['Segue dados de hoje. \n',
'\n',
'\n',
'\n',
' \n',
'\n',
'\n',
'\n',
'WDO\n',
'\n',
'\n',
'\n',
'\t\t\n',
'\n',
'Média\n',
'\n']