import dataset import traceback db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/google_poi?charset=utf8mb4') cursor=db.query('select distinct keyword from shop_list2') lst=[] for c in cursor: print(c['keyword']) lst.append(c['keyword']) for l in lst: try: db.query('insert into google_poi.areacodes (select num,"'+l+'",0 from lat_lon_loc) ') except: traceback.print_exc()