我有下面的剧本
#!/Users/admin/anaconda/bin/python
import geocoder
import unicodecsv
import logging
import csv
import time
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
pcode=[]
with open('locs2.csv', 'rb') as f:
reader = csv.DictReader(f)
for line in reader:
lat = float(line['lat'])
lon = float(line['lon'])
g = geocoder.google([lat,lon], method='reverse')
attempts = 1 # number of lookups
while not(g.ok) and attempts < 4:
logging.warning('Geocoding ERROR: {}'.format(g.debug()))
time.sleep(2) # 2 seconds are specified in the API. If you stillget errors, it's because you've reached the daily quota.
g = geocoder.google([lat,lon], method='reverse')
attempts += 1
if attempts > 3:
logging.warning('Daily quota of google lookups exceeded.')
break
pcode.append((lat, lon, g.postal))
logging.info('Geocoding SUCCESS: ({},{},{})'.format(lat,lon,pcode))
我试图把所有的脚本结果在一个文本文件与下面的命令行,但它不工作。为什么?你知道吗
sys.stdout = open ("Output.txt", "w")
更改日志记录配置以将日志发送到文件:
相关问题 更多 >
编程相关推荐