dataset對於操作JSON文件、NoSQL非常好用。 官方文檔:http://dataset.readthedocs.io/en/latest/ 補充: 連接mysql數據庫: db = dataset.connect('mysql://username:password@10.10.10.10/onlinedb?charset=utf8') (用戶名:username,密碼:password,數據庫地址(地址+端口):10.10.10.10,database名: onlinedb) 一定要注意指定字符編碼啊,被這個坑死了。 table = db['city'] #(選擇city表) user = table('name') # 找出表中'name'列屬性所有數據 res = db.query('select name from table limit 10') # 如果不需要查看全部數據的話最好用limit,因為全部數據的載入時間簡直不能忍啊 for x in res: print x['name'] # 選name字段的數據 在數據庫中查找是否有同時滿足多個條件的數據(find_one的速度讓人痛心啊):table.find_one(屬性1=屬性值1, 屬性2=屬性值2, ...)