Return from file reading function in python

1

I made this code snippet to loop through the contents of the list files.

lista_nome_base_docs = ['a.txt', 'b.txt', 'c.txt']
tamanho = len(lista_nome_base_docs)
print (tamanho)

lista_geral_arquivos = []


for i in range(tamanho):
     with open(lista_nome_base_docs[i],"r") as arquivo:
     conteudo = [line.strip() for line in arquivo if line.strip() != "" and line.strip() != "." and line.strip() != "\n" and line.strip() != "!" and line.strip() != "?" and line.strip() != ":" and line.strip() != "," and line.strip() != ""]
     lista_geral_arquivos.append(conteudo)

print (lista_geral_arquivos)

but my list list gets this content:

[['€\x03]q\x00]q\x01a.'], ['€\x03]q\x00]q\x01a.'], ['€\x03]q\x00]q\x01a.']]

Does anyone know how words appear instead of these strange characters? I already tried .read() and .readlines() and they are not putting every word in a list position but rather this lot of messy characters ...

    
asked by anonymous 06.10.2017 / 15:53

1 answer

2

What about:

arquivos = ['a.txt', 'b.txt', 'c.txt']
lista_geral = []

for nome in arquivos:

    with open( nome, "r") as arq:

        a = []

        for linha in arq:
            a.append(linha.strip())

    lista_geral.append(a)

print( lista_geral )
    
06.10.2017 / 16:50