Save data to a csv file

-3

I'm trying to save data to a csv file from fields:

def inserir():
    camp1 = str(ed1.get())
    camp2 = str(ed2.get())
    camp3 = str(ed3.get())

     with open("contatos.csv","w") as _file:
         _file.write("Nome;tel;endereço")
         _file.write(camp1)
         _file.write(camp2)
         _file.write(camp3)

return None
    
asked by anonymous 27.05.2018 / 16:16

2 answers

0

I do not remember if writelines works with variables, but basically that's it.

 fh = open(“contatos.csv”,”w”) 
 linhas_de_texto = [camp1, camp2, camp3] 
 fh.writelines(linhas_de_texto) 
 fh.close()

There you were trying to write only one variable line by line

    
27.05.2018 / 17:06
-1

I managed to resolve it

file.writelines(";".join([camp1,camp2,camp3]))
    
27.05.2018 / 19:19