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.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java 2D数组,查找包含元素   包含EBCDIC值的java打印字节数组未给出预期值   java应用程序重新启动,由于AndroidRuntime异常而无法运行   java在spring中对拦截器的使用   java ActiveMQ,代理接收要发送的消息的时间戳   JAVA:如何从需要启用Cookie的站点下载HTML文件?   邮件发送期间发生java证书错误   Java错误:类事务中的构造函数事务无法应用于给定类型   方法的Java对象空检查   Java如何在多个源文件夹之间使用全局变量?   二进制字符串到整数转换器中的java错误   java在关闭页面后保存数据   c#使用java客户端使用WCF restful Web服务?   java在从vimeo api获取后更改iframe src   API低于17的java Android AlertDialog setOnDismissListener   java如何将文本从对象的ArrayList设置为TextView?   java OpenCV Android imwrite给我一个蓝色图像   java能够在RecyclerView中同时单击两个项目   java将字节数组写入文件的快速方法