写入新文件,但它只适用于第一个新创建的文件。然后它返回其他新创建的文件,但没有写入行。求救!
这是我的代码:
with open('path to file') as csvfile:
readCSVstations = csv.reader(csvfile, delimiter=' ')
for i in range(len(lat)):
with open("path to new file/cap_" + str(lat[i]) + "_" + str(lon[i]) + ".dat", 'w') as f:
csv_writer=csv.writer(f, delimiter=' ')
for row in readCSVstations:
p1_lat=float(lat[i])
p1_lon=float(lon[i])
p2_lat=float(row[2])
p2_lon=float(row[3])
p1=(p1_lat,p1_lon)
p2=(p2_lat,p2_lon)
lat和long只是lat和long值的列表
x=(vincenty(p1,p2)).kilometers
if x <= 250:
csv_writer.writerow(row)