Python面向对象
Python面向对象
#coding:utf-8 #获取地址信息 import sys,requests,md5 #通过高德地图api获取地址信息 def get_geocodeG(address): result = {} par = {'address': address, 'key': 'cb649a25c1f81c1451adbeca73623251'} base = 'http://restapi.amap.com/v3/geocode/geo' response = requests.get(base, par) answer = response.json() result['address'] = address try: result['province'] = answer['geocodes'][0]['province'] result['city'] = answer['geocodes'][0]['city'] result['citycode'] = answer['geocodes'][0]['citycode'] result['district'] = answer['geocodes'][0]['district'] result['level'] = answer['geocodes'][0]['level'] result['adcode'] = answer['geocodes'][0]['adcode'] result['locationX'] = answer['geocodes'][0]['location'].split(',')[0] result['locationY'] = answer['geocodes'][0]['location'].split(',')[1] result['formatted_address'] = answer['geocodes'][0]['formatted_address'] except: pass return result #address = "台州市椒江区开元小区内" #result = get_geocodeG(address) #print result['district'],result['formatted_address'],result['locationX'],result['locationY'] #定义学校基础类 class School(object): '''学校基础类''' def __init__(self,id='',name='',type='',address='',postCode='',areaCode='',tel=''): self.id = id self.name = name self.type = type self.address = address self.postCode = postCode self.areaCode = areaCode self.tel = tel def __str__(self): return 'id:%s,name:%s,type:%s,'%(self.id,self.name,self.type) class Collage(School): def __init__(self,id='',name='',type='',address='',locationX='',locationY='',postCode='',areaCode='',tel='',fax='',url=''): super(Collage,self).__init__(id,name,type,address,postCode,areaCode,tel) self.locationX = locationX self.locationY = locationY self.fax = fax self.url = url def __str__(self): return 'id:%s,name:%s,type:%s,url:%s'%(self.id,self.name,self.type,self.url) #1133000002 仙居县中心幼儿园 城关南门街186号 317300 0576 89386288 school = School('1133000002','仙居县中心幼儿园','幼儿园','城关南门街186号','317300','0576','89386288') print school.name print school #4133010335 浙江大学 高等学校 杭州市西湖区余杭塘路866号 120.0213889 30.22083333 310058 0571 88981583 88981358 www.zju.edu.cn collage = Collage('4133010335','浙江大学','高等学校','杭州市西湖区余杭塘路866号','120.0213889','30.22083333','310058','0571','88981583','88981583','www.zju.edu.cn') print collage ''' print School.__name__ print School.__doc__ print School.__bases__ print School.__dict__ print School.__module__ '''