我有以下代码:
# -*- coding: utf-8 -*-
import csv, geocoder
def extract_address(lat="", lng=""):
if lat and lng:
g = geocoder.google([lat, lng], method='reverse')
if g:
if g.street is not None:
postal = g.postal
housenumber = g.housenumber
if g.housenumber is None:
housenumber = ""
if g.postal is None:
postal = ""
address = str(g.street.encode("utf-8")) + ", " + str(housenumber.encode("utf-8")) + ", " + str(postal.encode("utf-8")) + " " + str(g.city.encode("utf-8")) + ", " + str(g.country_long.encode("utf-8"))
print type(address)
return address.decode('utf-8')
with open('my_prueba.csv', 'w') as t:
spamwriter = csv.writer(t, delimiter=';', quotechar='"', quoting=csv.QUOTE_MINIMAL, lineterminator='\n')
spamwriter.writerow(['st_y', 'st_x', 'Address'])
address = extract_address('some_lat', 'some_lng'))
print address
spamwriter.writerow([str(lat), str(lng), str(address.encode('utf-8'))])
这是输出:
<type 'str'>
Calle Hernán Cortés, 16, 28004 Madrid, Spain
但是我打开csv文件后得到的是:
我一直在尝试很多东西,并阅读不同的相关stackoverflow帖子,但没有...任何人都可以帮我这个吗?!
提前致谢!
编辑:我想将其转换为Excel文件。如果我用另一个应用程序打开csv,列将以我不想要的另一种方式分隔。当我用excel
打开csv文件时,上面的代码给了我正确的分隔