python的一个选择性的、漂亮的dir打印实用程序。
pdir的Python项目详细描述
pdir:python的选择性、漂亮的dir打印实用性
dir()是python中对开发人员和调试器非常有用的实用函数, 返回包含给定对象属性的名称列表, 以及可从中获取的属性。 然而,很多时候,所有这些名字都会被窃听。
case-1:假设您真正感兴趣的是只知道python“list”提供的有用方法。 而且您不喜欢使用“dir(list)”导致的不可读、未过滤的混乱。
案例二:你真的很喜欢unix的“grep”工具,你想要这样的工具 它允许您在一个简单的调用中regex过滤dir()的结果。
那么pdir应该对你很有用。 我写这篇文章是因为这样的东西对我很有帮助,我很快就需要 只列出命名空间提供的重要功能;喜欢阅读干净漂亮的东西; 非常喜欢unix的“grep”实用程序。
您的新dir()朋友-
- 基于rdir-regex的目录过滤实用程序(可选引用:rd)
- pdir-漂亮、方便的dir打印和帮助(可选参考:pd)
快速启动
pdir
安装此包后,可以使用从pdir导入pdir函数, 把它当作你的新朋友。
例如:
>>>frompdirimportpdir>>>pdir(list)['append','count','extend','index','insert','pop','remove','reverse','sort']
现在让我们将其与打印的目录(列表)进行比较:
>>>dir(list)['__add__','__class__',...........................................................................................................................................'append','count','extend','index','insert','pop','remove','reverse','sort']
有些元素在这里用点(…)代替。
以前的不是更干净更好吗?
pdir>;v0.1还附带帮助实用程序(alpha)
>>>pdir(list,help=True)-append-L.append(object)--appendobjecttoend--count-L.count(value)->integer--returnnumberofoccurrencesofvalue--extend-L.extend(iterable)--extendlistbyappendingelementsfromtheiterable-
pd是上述pdir函数的替代引用。
>>>frompdirimportpd>>>pd(list)# Is same as pdir used in the example before.
rdir
在解释了pdir之后,它可能是这个包更方便的一面, rdir是这里更强大和有用的组件。 它允许您运行regex过滤器来限制dir返回的名称。
>>>frompdirimportrdir>>>rdir(list,'in')['__contains__','__init__','index','insert']>>>>>># The above shows a list of items that match the regex='in' filter. Very similar to the unix grep utility.>>>>>># To get an inverse list (NOT matching regex) pass the *inv=True* parameter. keyword "inv" is optional.>>>rdir(list,'__',True)>>>['append','count','extend','index','insert','pop','remove','reverse','sort']>>># ^ returned a list without any '__' (underscores).
pdir函数本身在内部使用上依赖于rdir。
rdir->; *默认情况下不美观打印并返回可分配给其他对象的列表。 *要启用漂亮的打印,必须禁用return,方法是提供ret=false作为附加参数。
注释
- pdir is essentially a wrapper on rdir, which in itself is a wrapper around the Python dir function.
- The code for this tool is available here.
- Would be glad to see anyone interested in contributing.
- You can email me or leave an issue on github suggesting improvements.