各种dict、list和其他数据结构的Python函数。
datafunc的Python项目详细描述
数据函数
用于dict、list和其他数据结构的各种函数的Python包。在
变更日志
- ^{str1}$11/17/2020-0.0.4:添加缺少的类型注释。生成文档。在
- ^{str1}$11/17/2020-0.0.3:添加了
duplicate()
和{}方法。添加了一些缺少的类型声明。在 - 11/15/2020-0.0.2:类型注释和次要重构。在
- ^{str1}$11/15/2020-0.0.1:初始方法。在
参考文献
展平
flatten(var:object)->Data
遍历dict-like对象并返回一个包含all的新对象 相同的值,但只有一层深。在
参数:
var
:要展平的类Dict变量。在
返回:
像dict一样的数据对象。在
iterable
^{pr 2}$Determine whether or not the input variable is iterable.
Arguments:
- ^{
}: Any
Returns:
Boolean
listlike
^{pr 3}$Determine if the input variable is list-like (Not a str, not dict-like, but is iterable)
Arguments:
- ^{
}: Any
Returns:
Boolean
mo_dotian
^{pr 4}$Determine whether or not the input var is a mo-dots type.
Arguments:
- ^{
}: Any
Returns:
Boolean
apply_if
^{pr 5}$Apply func_to_apply() to var if condiction() else apply else_func()
Arguments:
- ^{
}: Callable to pass var to if condition(var) return true - ^{
}: Variable to test against condition and return through func_to_apply() or else_func() - ^{
}: Callable to test var against. Should return a Boolean. - ^{
}: Callable to return var through if condition(var) returns False.
Returns:
func_to_apply(var) if condition(var) returns True, otherwise else_func(var)
dictlike
^{pr 6}$Determine whether or not var is dict-like (Can contain dict-like items).
Arguments:
- ^{
}: Any variable to check
Returns:
Boolean
nestable
^{pr 7}$Will return True if input var is either list-like or dict-like.
Arguments:
- ^{
}: Any input variable.
Returns:
Boolean
jsonify_nestable_vals
^{pr 8}$Convert any nestable (Dict-like or list-like) to a dict-like mo-dots Data object of obj's values as JSON strings.
Arguments:
- ^{
}: Any nestable variable.
Returns:
A dict-like mo-dots Data object of obj's values as JSON strings.
compare
^{pr 9}$Compare dict-like variable d1 to dict-like variable d2 and return a dict-like mo-dots Data object of what's been added, removed, modified, or remained equal in d2
Arguments:
- ^{
}: Dict-like variable as the base variable. - ^{
}: Dict-like variable to compare/contrast to d1
Returns:
Dict-like mo-dots Data object of differences between d1 and d2.
function_of
^{pr 10}$Determine whether or not a function's (func) name exists in tuple of strings (func_names).
Arguments:
- ^{
}: The callable function to test. - ^{
}: Tuple of function names as strings ("func1", "func2", "func3,)
Returns:
Boolean True (func is of func_names) or False (func is not of func_names)
basevals
^{pr 11}$This method receives a dict and list of attributes to return the innermost value of the given dict-like var. This function seems stupid and I don't recall what it was for.
vivify
^{pr 12}$Adds the last attr variable passed to the dict-like "var" in the hierarchy mentioned via the prior *attrs For ex: vivify(animals, "cat", "leg","fingers", 4) is equivalent to animals["cat"]["leg"]["fingers"]=4 This method creates necessary objects until it reaches the final depth This behaviour is also known as autovivification and plenty of implementation are around This implementation addresses the corner case of replacing existing primitives https://gist.github.com/hrldcpr/2012250#gistcomment-1779319
复制
duplicate(data:object)->object
方便方法复制.deepcopy()
参数:
data
:任何dict、mo点或dotty对象。在
返回:
数据的深层拷贝。在
添加同级
add_sibling(data:object,node_path:List,new_key:str,new_data:Any,_i:int=0)
用于添加同级数据节点的遍历安全方法。在
参数:
data
:正在遍历的数据对象。在node_path
:指向要创建的节点的路径段列表 兄弟姐妹。与遍历()的节点路径相同new_key
:要创建的同级键。在new_data
:要存储在密钥处的新数据。在_i
:节点路径迭代器的深度。在
- 项目
标签: