0
Good afternoon! I’ve been in a jam for days because I can’t seem to make sense of the problem I’m having. I’m making a query to record data in a type str in python. This query goes through the query and where the values of a column are equal it save in a single row and when finished goes to the next item. the problem is that in the lines where the column value repeats it also repeats the write in the file that duplicates the data.
Follow the image where the file is with the duplicated lines and the code I use to generate the file.
cursorVendas = con.cursor()
cursorVendaProdutos = con.cursor()
base = ''
cursorVendas.execute('select * from venda')
for vendas in cursorVendas:
quantidade = cursorVendaProdutos.execute('select desccompleta from venda where nrodocto = ' + str(vendas[0]))
i = 1
for produtos in cursorVendaProdutos:
print(produtos)
if (i == quantidade) :
base = base + produtos[0]
else:
base = base + produtos[0] + ','
i += 1
base = base + '\n'
print(base)
arquivo = open("base_import.csv", "w")
arquivo.write(base)
arquivo.close()
If I put in the distinct in select it won’t bring me all the coupons, I need all the coupons as the products are different in each coupon.
– Andressa M