pyefun.模块.通用实用函数 module¶
提示
实用函数
- class pyefun.模块.通用实用函数.临时目录[源代码]¶
基类:
ubelt.util_path.TempDir
用于创建和清理临时目录的上下文。
#Example: # with 临时目录() as self: # dpath = self.dpath # print(dpath) # assert 文件是否存在(dpath) # assert not 文件是否存在(dpath)
#Example: # self = 临时目录() # dpath = self.ensure() # assert exists(dpath) # self.cleanup() # assert not exists(dpath)
- class pyefun.模块.通用实用函数.分块(items, 分块数量=None, 创建块数=None, 创建数量=None, 边界模式='none')[源代码]¶
基类:
ubelt.util_list.chunks
- pyefun.模块.通用实用函数.取缓存目录(name)[源代码]¶
# The resource root directory is # ~/AppData/Roaming on Windows, # ~/.config on Linux and ~/Library/Application Support on Mac. # The cache root directory is ~/AppData/Local on Windows, # ~/.config on Linux and ~/Library/Caches on Mac.
- pyefun.模块.通用实用函数.字典_取最小值(indexable, key=None)[源代码]¶
# assert argmin({‘a’: 3, ‘b’: 2, ‘c’: 100}) == ‘b’ # assert argmin([‘a’, ‘c’, ‘b’, ‘z’, ‘f’]) == 0 # assert argmin([[0, 1], [2, 3, 4], [5]], key=len) == 2 # assert argmin({‘a’: 3, ‘b’: 2, 3: 100, 4: 4}) == ‘b’ # assert argmin(iter([‘a’, ‘c’, ‘A’, ‘z’, ‘f’])) == 2
- pyefun.模块.通用实用函数.数组_去重复(items, key=None)[源代码]¶
# import ubelt as ub # import six # items = [‘A’, ‘a’, ‘b’, ‘B’, ‘C’, ‘c’, ‘D’, ‘e’, ‘D’, ‘E’] # unique_items = list(ub.unique(items, key=six.text_type.lower)) # assert unique_items == [‘A’, ‘b’, ‘C’, ‘D’, ‘e’] # unique_items = list(ub.unique(items)) # assert unique_items == [‘A’, ‘a’, ‘b’, ‘B’, ‘C’, ‘c’, ‘D’, ‘e’, ‘E’]
- pyefun.模块.通用实用函数.数组_取唯一值的索引(items, key=None)[源代码]¶
# import ubelt as ub # import six # items = [‘A’, ‘a’, ‘b’, ‘B’, ‘C’, ‘c’, ‘D’, ‘e’, ‘D’, ‘E’] # unique_items = list(ub.unique(items, key=six.text_type.lower)) # assert unique_items == [‘A’, ‘b’, ‘C’, ‘D’, ‘e’] # unique_items = list(ub.unique(items)) # assert unique_items == [‘A’, ‘a’, ‘b’, ‘B’, ‘C’, ‘c’, ‘D’, ‘e’, ‘E’]
- pyefun.模块.通用实用函数.数组_取唯一值的逻辑值(items, key=None)[源代码]¶
# import ubelt as ub # import six # items = [‘A’, ‘a’, ‘b’, ‘B’, ‘C’, ‘c’, ‘D’, ‘e’, ‘D’, ‘E’] # unique_items = list(ub.unique(items, key=six.text_type.lower)) # assert unique_items == [‘A’, ‘b’, ‘C’, ‘D’, ‘e’] # unique_items = list(ub.unique(items)) # assert unique_items == [‘A’, ‘a’, ‘b’, ‘B’, ‘C’, ‘c’, ‘D’, ‘e’, ‘E’]
- pyefun.模块.通用实用函数.数组_取最小值(indexable, key=None)[源代码]¶
# assert argmin({‘a’: 3, ‘b’: 2, ‘c’: 100}) == ‘b’ # assert argmin([‘a’, ‘c’, ‘b’, ‘z’, ‘f’]) == 0 # assert argmin([[0, 1], [2, 3, 4], [5]], key=len) == 2 # assert argmin({‘a’: 3, ‘b’: 2, 3: 100, 4: 4}) == ‘b’ # assert argmin(iter([‘a’, ‘c’, ‘A’, ‘z’, ‘f’])) == 2
- pyefun.模块.通用实用函数.数组_是否全部相同(iterable, eq=<built-in function eq>)[源代码]¶
#allsame([1, 1, 1, 1]) # True #allsame([]) # True #allsame([0, 1]) # False #iterable = iter([0, 1, 1, 1]) #next(iterable) #allsame(iterable) # True #allsame(range(10)) # False #allsame(range(10), lambda a, b: True) # True
- pyefun.模块.通用实用函数.数组_构建逻辑值列表(indices, maxval=None)[源代码]¶
# import ubelt as ub #indices = [0, 1, 4] #mask = ub.boolmask(indices, maxval=6) #assert mask == [True, True, False, False, True, False] #mask = ub.boolmask(indices) #assert mask == [True, True, False, False, True]
- pyefun.模块.通用实用函数.文本_水平合并(args, sep='')[源代码]¶
# import ubelt as ub # B = ub.repr2([[1, 2], [3, 457]], nl=1, cbr=True, trailsep=False) # C = ub.repr2([[5, 6], [7, 8]], nl=1, cbr=True, trailsep=False) # args = [‘A = ‘, B, ‘ * ‘, C] # print(文本_水平合并(args)) # A = [[1, 2], * [[5, 6], # [3, 457]] [7, 8]]
- pyefun.模块.通用实用函数.查找可执行文件(名称, 匹配所有=False, 路径=None)[源代码]¶
# 查找可执行文件(‘ls’) # 查找可执行文件(‘ping’) # assert 查找可执行文件(‘which’) == 查找可执行文件(查找可执行文件(‘which’)) # 查找可执行文件(‘which’, 匹配所有=True) # 查找可执行文件(‘ping’, 匹配所有=True) # 查找可执行文件(‘cmake’, 匹配所有=True) # 查找可执行文件(‘nvcc’, 匹配所有=True) # 查找可执行文件(‘noexist’, 匹配所有=True)
- pyefun.模块.通用实用函数.查找文件或目录(名称, 路径=None, 精确=False)[源代码]¶
# list(查找文件或目录(‘ping’, exact=True)) # list(查找文件或目录(‘bin’)) # list(查找文件或目录(‘bin’)) # list(查找文件或目录(‘cc’)) # list(查找文件或目录(‘cmake*’))