Error with append with python csv file

Asked

Viewed 132 times

0

I have a code that sends information to a csv. When it runs the first time it writes the file normally, but when it runs the second time it should add a new line in the file it ends up overwriting the whole file:

        with open('\\offline.csv', 'a', encoding='utf-8', newline='') as f:
        try:
            writer = csv.writer(f)
            writer.writerow((hw_Processador(), hw_Fabricante_PlacaMae(), hw_Modelo_PlacaMae(), hw_NS_PlacaMae(), sis_HostName(), sis_SistemaOperacional(), sis_Data_Instalacao(), sis_Dominio(), sis_Arquitetura(), sis_Usuario_Atual(), rede_IPV4(), rede_MacAddress(), rede_DNS(), hw_Memoria_RAM(), hw_HD(), nome_tecnico, local_mapeamento))
            print('SEM CONEXAO! ARQUIVO CSV GERADO.')
        finally:
            f.close()

Would anyone have any idea what might be going on?

  • 3

    For what tested here the code is working normally. Can elaborate a [mcve]?

  • @Andersoncarloswoss was doing minimal reproducible example and discovered the error during the process. Thank you very much, it was a function within my code.

  • @Algeujunior You could put the answer to the problem.

1 answer

-2

 with open('\\offline.csv', 'a', encoding='utf-8', newline='') as f:

Aim to do this line without the newline:

 with open('\\offline.csv', 'a', encoding='utf-8') as f:
  • 1

    Why?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.