本文整理汇总了Python中sqlitedict.SqliteDict.get方法的典型用法代码示例。如果您正苦于以下问题:Python SqliteDict.get方法的具体用法?Python SqliteDict.get怎么用?Python SqliteDict.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlitedict.SqliteDict
的用法示例。
在下文中一共展示了SqliteDict.get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _import_sql_data
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import get [as 别名]
def _import_sql_data(data_dir):
file_path = os.path.join(data_dir, DATA_FILE)
# Find out what format we have
with sqlite3.connect(file_path) as conn:
try:
conn.execute('select count(*) from zipgun_info')
zipgun_info = SqliteDict(file_path, tablename='zipgun_info')
version = zipgun_info.get('version', 0)
except sqlite3.OperationalError:
version = 0
if version == 0:
country_postal_codes = SqliteDict(file_path)
elif version == 1:
country_postal_codes = {}
for country_code in zipgun_info['country_codes']:
if country_code in country_postal_codes:
raise ValueError('Duplicate entry found for {}'.format(
country_code))
country_postal_codes[country_code] = SqliteDict(
file_path, tablename='zg_{}'.format(country_code),
journal_mode='OFF')
zipgun_info.close()
else:
raise ValueError('Unknown data file version {}'.format(version))
return country_postal_codes