递归探索任意Python对象的工具。
项目描述
pynaunt 允许您深入探索和检查任意Python对象。
例如,我们可以探索一下 os 模块
>>> from pynaut import Container >>> import os >>> obj = Container(os) >>> len(list(obj.children)) 203 >>> w = list(obj.grep_attr_names('wait')) >>> len(w) 23 >>> [a.name for a in w] ['wait', 'wait4', 'wait3', 'wait', 'wait4', 'wait3', 'waitpid', 'wait', 'wait4', 'wait3', 'waitpid', 'wait', 'wait4', 'wait3', 'wait', 'wait4', 'wait3', 'waitpid', 'waitpid', 'waitpid', 'waitget', 'waitget', 'waitget'] >>> from types import ModuleType >>> test = lambda c: isinstance(c.obj, (bool, list, ModuleType)) >>> foo = list(obj.get_attr_matches(test)) >>> len(foo) 620 >>> [a.name for a in foo][:10] ['UserDict', 'errno', 'path', 'auto_magic', 'genericpath', 'stat', 'os', 'UserDict', 'errno', 'path']
此外,还支持在整个对象树中搜索满足任意条件的(名称,属性)对。
pynaut 还包括一个基于curses的非常基本的界面( pynaut_curses ),允许您通过遍历属性树来探索对象。