本文整理汇总了Python中tablib.Dataset.dict方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.dict方法的具体用法?Python Dataset.dict怎么用?Python Dataset.dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tablib.Dataset
的用法示例。
在下文中一共展示了Dataset.dict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dataset
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import dict [as 别名]
def dataset(data, headers=None):
""" `data` is a list of dicts.
"""
dataset = Dataset()
dataset.dict = data
if headers:
dataset.headers = headers
return dataset
示例2: read_database
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import dict [as 别名]
def read_database():
with open(COMO_BATTERY_FILE, 'r') as como:
data = Dataset(headers=['time', 'capacity', 'cycles'])
# http://stackoverflow.com/questions/10206905/
# how-to-convert-json-string-to-dictionary-and-save-order-in-keys
data.dict = json.loads(
zlib.decompress(como.read()),
object_pairs_hook=collections.OrderedDict)
return data
示例3: cmd_import
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import dict [as 别名]
def cmd_import(args):
if not os.path.exists(COMO_BATTERY_FILE):
current_dataset = create_database()
else:
current_dataset = read_database()
if os.path.exists(args.get(0)):
import_dataset = Dataset()
with open(os.path.expanduser(args.get(0)), "r") as import_file:
import_dataset.csv = import_file.read()
import_dataset.dict = map(import_format, import_dataset.dict)
new = current_dataset.stack(import_dataset).sort('time')
with open(COMO_BATTERY_FILE, 'w') as como:
como.write(zlib.compress(new.json))
puts(colored.white("battery statistics imported"))
else:
error("Couldn't open file: %s" % args.get(0))