本文整理匯總了Python中param.Dict方法的典型用法代碼示例。如果您正苦於以下問題:Python param.Dict方法的具體用法?Python param.Dict怎麽用?Python param.Dict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類param
的用法示例。
在下文中一共展示了param.Dict方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: define
# 需要導入模塊: import param [as 別名]
# 或者: from param import Dict [as 別名]
def define(cls, name, **kwargs):
"""
Utility to quickly and easily declare Stream classes. Designed
for interactive use such as notebooks and shouldn't replace
parameterized class definitions in source code that is imported.
Takes a stream class name and a set of keywords where each
keyword becomes a parameter. If the value is already a
parameter, it is simply used otherwise the appropriate parameter
type is inferred and declared, using the value as the default.
Supported types: bool, int, float, str, dict, tuple and list
"""
params = {'name': param.String(default=name)}
for k, v in kwargs.items():
kws = dict(default=v, constant=True)
if isinstance(v, param.Parameter):
params[k] = v
elif isinstance(v, bool):
params[k] = param.Boolean(**kws)
elif isinstance(v, int):
params[k] = param.Integer(**kws)
elif isinstance(v, float):
params[k] = param.Number(**kws)
elif isinstance(v, str):
params[k] = param.String(**kws)
elif isinstance(v, dict):
params[k] = param.Dict(**kws)
elif isinstance(v, tuple):
params[k] = param.Tuple(**kws)
elif isinstance(v, list):
params[k] = param.List(**kws)
elif isinstance(v, np.ndarray):
params[k] = param.Array(**kws)
else:
params[k] = param.Parameter(**kws)
# Dynamic class creation using type
return type(name, (Stream,), params)
示例2: LiteralInputTyped
# 需要導入模塊: import param [as 別名]
# 或者: from param import Dict [as 別名]
def LiteralInputTyped(pobj):
if isinstance(pobj, param.Tuple):
return type(str('TupleInput'), (LiteralInput,), {'type': tuple})
elif isinstance(pobj, param.Number):
return type(str('NumberInput'), (LiteralInput,), {'type': (int, float)})
elif isinstance(pobj, param.Dict):
return type(str('DictInput'), (LiteralInput,), {'type': dict})
elif isinstance(pobj, param.List):
return type(str('ListInput'), (LiteralInput,), {'type': list})
return LiteralInput