我有一个小问题我总是得到错误:
TypeError:无法连接“str”和“list”对象
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()
我找不到我的错误。