How to open a csv created in Python without opening an import screen?

1

I have already created a csv in Python in several ways as can be seen below, but every time I open the file opens the import screen as below.

Why does this happen?

And how can I make the file open directly within the csv defaults?

Detail: I'm using LibreOffice to open the file.

Code 1:

import csv
csvfile = "arquivo.csv"
f=open(csvfile,'wb') # abre o arquivo para escrita apagando o conteúdo
csv.writer(f, delimiter =' ',quotechar =',',quoting=csv.QUOTE_MINIMAL)

Code 2:

import csv

c = csv.writer(open("teste.csv", "w"))

Code 3:

Arquivo = open(Diretorio + "relatorios/" + nome_arquivo_csv, "a")
            Arquivo.write('\n'  +valores_str + '\t' + medidas_str)
            Arquivo.close()

    
asked by anonymous 24.01.2018 / 16:40

1 answer

4

Philippe, as commented above, I do not think it's a problem related to python or the way you generate the file, but rather to LibreOffice.

Anyway a possible solution to this would be to save your content in one of the formats that LibreOffice supports without prior formatting, such as xlsx .

In a short search, I found this example , using the pandas . I tested it with python 3.6 and it worked.

 import pandas

 data = pandas.read_csv('example.csv')
 writer = pandas.ExcelWriter('example.xlsx')
 to_excel = data.to_excel(writer, index=False)
 writer.save()

For this example, I have used the following CSV.

id,first_name,last_name,email,gender,ip_address
1,Aube,Pynner,[email protected],Male,202.161.177.42
2,Em,McFaul,[email protected],Male,16.179.223.5
3,Nico,Belford,[email protected],Male,239.143.91.73

I hope I have helped.

Att,

    
24.01.2018 / 17:14