I want to save in a new txt file a copy of another txt in Python

0
arq = open("/Users/DIGITAL/Desktop/Python/novo.txt", "w")
arq.write(palavras)
arq.close()

I'm using this code, but it only accepts string.

    
asked by anonymous 09.10.2017 / 20:54

1 answer

1

You can do something like this:

with open('test.txt', 'r') as arquivo_existente, open('novo_arquivo.txt', 
'w') as novo_arquivo:
    for linha in arquivo_existente.readlines():
        novo_arquivo.write(linha)

When executing the above code, the content of arquivo_existente.txt will be copied to the file novo_arquivo.txt

    
09.10.2017 / 21:03