base_processor.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:geocoder-ie 作者: devgateway 项目源码 文件源码
def save_to_tsv(out_file, geocoding, out_path=''):
        try:
            out_file_with_extension = '{}.tsv'.format(out_file)
            with open(os.path.realpath(os.path.join(out_path, out_file_with_extension)), 'w+', newline='') as csvfile:
                fieldnames = ['geonameId', 'name', 'toponymName', 'fcl', 'fcode', 'fcodeName', 'fclName', 'lat', 'lng',
                              'adminCode1', 'adminName1', 'adminCode2', 'adminName2', 'adminCode3', 'adminName3',
                              'adminCode4',
                              'adminName4', 'countryName', 'population', 'continentCode', 'countryCode',
                              ]
                writer = csv.DictWriter(csvfile, fieldnames=fieldnames, delimiter='\t', quotechar='"',
                                        quoting=csv.QUOTE_MINIMAL)
                writer.writeheader()
                id, locations = geocoding[0]
                for data in locations:
                    writer.writerow(data)
            csvfile.close()
            return out_file_with_extension
        except Exception as e:
            logger.error('Error while writing tsv file {}'.format(e))
            raise
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号