2017-04-30 11 views
0

辞書をUnQLiteデータベースに保存したいので、後で使用することができます。文字列としてしかしUnQLite店舗それは:Python:UnQLiteで辞書を保存するには?

>>> from unqlite import UnQLite 
>>> db = UnQLite() 
>>> db['dict'] = {'a': 5} 
>>> db['dict'] 
"{'a': 5}" 

答えて

1

私はその後、彼らのネイティブ型でデータを取得collectionを使用することができることを考え出しました。

>>> from unqlite import UnQLite 
>>> db = UnQLite() 
>>> colors = db.collection('colors') 
>>> if not colors.exists(): 
... colors.create() 
... 
>>> colors.store([{'name': 'red', 'code': '#ff0000'}, {'name': 'green', 'code': '#00ff00'}]) 
1 
>>> colors.all() 
[{'code': '#ff0000', 'name': 'red', '__id': 0}, {'code': '#00ff00', 'name': 'green', '__id': 1}] 
関連する問題