本文整理汇总了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