python - splitting lists and values -


within python script have 2 floating values , 2 lists write in csv file. lonwgs84 , latwgs84 floating values , col1s , col2s lists. when write csv file with:

with open(ausgabe, "wb") f:       datawriter = csv.writer(f)     each in zip(lonwgs84 , latwgs84, col1s, col2s):         cols = each[0] , each[1], each[2] + each[3]         datawriter.writerow(cols) 

i following output:

51.821336803,11.6756790532,"['~11:16:05.833', '$gpgga', '091607.00', '5149.28020818', 'n', '01140.54074319', 'e', '', '', '000.01']" 

but need is:

51.821336803,11.6756790532,~11:16:05.833,$gpgga,091607.00,5149.28020818,n,01140.54074319,e,,,000.01 

i tried split, seem work strings. maybe has idea how this? lot!

simply slice row first 2 elements, concatenate 3rd , 4th:

datawriter.writerow(each[:2] + each[3] + each[4]) 

alternatively, unpack elements first:

for fp1, fp2, lst1, lst2 in zip(lonwgs84 , latwgs84, col1s, col2s):     datawriter.writerow([fp1, fp2] + lst1 + lst2) 

demo:

>>> [fp1, fp2] + lst1 + lst2 [51.821336803, 11.6756790532, '~11:16:05.833', '$gpgga', '091607.00', '5149.28020818', 'n', '01140.54074319', 'e', '', '', '000.01'] 

you created tuple of first 2 elements, plus second 2 elements concatenated +:

cols = each[0], each[1], each[2] + each[3] 

resulting in nested structure of (each[0], each[1], [elements of each[2] , each[3]]).


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -