0
I have a function that returns a line and this should be inserted in a CSV file. The line has the following structure when returned by the function: ['x' - 'y', 'z', ['a', 'b', 'c', 'd', 'e', 'f']]
.
When I try insertion, using the method csv.writerow
, all characters are understood as a field. And that’s not the behavior I need.
The above row for the purpose of the application should be inserted as follows: x - y
, the first field; z
, the second; and ['a', 'b', 'c', 'd', 'e', 'f']
, the third and last.
Some fellow went through similar situation that could help me?
What I tried to do:
Code for insertion:
with open(arquivoSaida, 'at') as resultado:
arqGravar = csv.writer(resultado)
arqGravar.writerow(comparaNumeros(linhaAnterior, linhaPosterior))
Function generating the output to be inserted:
def comparaNumeros(linha, proxima):
numerosRep = []
totalRep = 0
i = 1
while i <= 15:
j = 1
while j <= 15:
if linha[i] == proxima[j]:
totalRep += 1
numerosRep.append(linha[i])
break
else:
j += 1
i += 1
csvLinha = linha[0] + " - " + proxima[0] + "," + str(totalRep) + "," + str(numerosRep)
#print(csvLinha)
return csvLinha
What language? Could you put your code in the question?
– Woss
The language is python.
– Francisco