CSV to KML via Python
Question: I have a little problem I always get the error:

> TypeError: cannot concatenate 'str' and 'list' objects
    
    
    import csv
    import os
    fp = "filepath/testfile.csv"
    file = open(fp)
    lines =file.readlines()
    for line in lines:
        line = line.strip()
        fields = line.split(',') #comma seperated
        branch = fields[0].split() #splitting
        lat = fields[1].split()
        lng = fields[2].split()
        web = fields[3].split()
        email = fields[4].split()
        adress = fields[5].split()
    
        print ("branch: " + branch) #print splitted
        print ("lat: " + lat)
        print ("lng: " + lng)
        print ("web :" + web)
        print ("email: " + email)
        print ("address: " + address)
    
    f = open('filepath/csv2kml.kml', 'w')
    fname = "testing_Actions"
    #Writing the kml file.
    f.write("<?xml version='1.0' encoding='UTF-8'?>\n")
    f.write("<kml xmlns='http://earth.google.com/kml/2.1'>\n")
    f.write("<Document>\n")
    f.write("   <name>" + fname + '.kml' +"</name>\n")
    for row in lines:
        f.write("   <Placemark>\n")
        f.write("       <ExtendedData>\n")
        f.write("           <Data name=the branch name>\n")
        f.write("               <value>\n")
        f.write("               " + str(branch) + "\n")
        f.write("               </value>\n")
        f.write("           </Data>\n")
        f.write("           </Data name=Web>\n")
        f.write("               <value>\n")
        f.write("               " + str(web) +"\n")
        f.write("               </value>\n")
        f.write("           </Data>\n")
        f.write("           </Data name=email>\n")
        f.write("               <value>\n")
        f.write("               " + str(email) + "\n")
        f.write("               </value>\n")
        f.write("           </Data>\n")
        f.write("       <description>" + str(address) + "</description>\n")
        f.write("       <Point>\n")
        f.write("           <coordinates>" + str(lat) + "," + str(lng) + "</coordinates>\n")
        f.write("       </Point>\n")
        f.write("   </Placemark>\n")
    f.write("</Document>\n")
    f.write("</kml>\n")
    print ("File Created. ")
    f.close
    file.close()
    

I cannot find my error.


Answer: "_I cannot find my error_ "

You can. If you read the error message completely, it tells you also, in which
lines the error occurred.

Was it here?

    
    
    print ("branch: " + branch) #print splitted
    

and in the following lines you try to concatenate string `"branch"` and a list
`branch`.

Try to replace it with:

    
    
    print ("branch: {}".format(branch)) #print splitted
    

