Python写入临时csv文件不起作用

时间:2018-11-26 21:23:36

标签: python python-2.7

我不知道为什么这行不通。

def lat_long(city):
    geocode_result = requests.get('http://www.datasciencetoolkit.org/twofishes?query= "city"')
    for interpretation in geocode_result["interpretations"]:
        if interpretation["where"] == city:
            return interpretation["feature"]["geometry"]["center"]

我的输入文件是键/值元组列表形式的一些RDD。我想创建一些临时的csv文件,以后可以使用。

打印行给我类似[47.31709671020508,79,3.0,1542924171526,8.521432876586914]的信息。但是,如果我尝试从文件中读取

def write_csv(partition):  
  field_names = ['Latitude','Longitude','GPSTimeUTC', 'Speed', 'Bearing']
  with tempfile.NamedTemporaryFile(delete=False) as keyfile:
    writer = csv.writer(keyfile)
    writer.writerow(field_names)
    for row in partition:
      row = row.asDict()
      row = {key: value for key, value in row.items() if key in field_names}
      print row
      writer.writerow(list(row.values()))

它什么也不会返回(并且是否在前面的with子句中也没关系)

提前谢谢

0 个答案:

没有答案
相关问题