Package: pdir
pdir: Selective, Pretty dir printing utlity for Pythondir() is a very useful utility function in python for developers & debuggers,
which returns a list of names comprising the attributes of the given object,
and of attributes reachable from it.
However, a lot many times all those names can be bugging.Case-1: Say you are really interested in knowing only the useful methods a Python “list” offers.
And you do not like the unreadable, unfiltered mess resulting from using “dir(list)”.Case-2: You really love the unix “grep” tool and you want something like that
which allows you to regex filter the results of dir() in a simple call.Then pdir should be very useful for you.
I wrote this bit because something like this is very helpful to me, who quickly needs a
list of only the important functions a namespace offers; likes reading clean pretty stuff;
and really loves the unix “grep” utility.Your new dir() friends-rdir - Regex based dir filtering utility (alternative reference:rd)pdir - Pretty, convenient dir printing with help (alternative reference:pd)QuickstartpdirYou can use import thepdirfunction from pdir after installing this package,
and consider it as your new dir() friend.An example:>>>frompdirimportpdir>>>pdir(list)['append','count','extend','index','insert','pop','remove','reverse','sort']Now lets compare this with what dir(list) prints:>>>dir(list)['__add__','__class__',...........................................................................................................................................'append','count','extend','index','insert','pop','remove','reverse','sort']Some of the elements are substituted with dots (…) here.Wasn’t the earlier one clean and better?pdir > v0.1 also ships with a help utility (alpha)>>>pdir(list,help=True)-append-L.append(object)--appendobjecttoend--count-L.count(value)->integer--returnnumberofoccurrencesofvalue--extend-L.extend(iterable)--extendlistbyappendingelementsfromtheiterable-pdis the alternative reference to the pdir function explained above.>>>frompdirimportpd>>>pd(list)# Is same as pdir used in the example before.rdirHaving explained pdir, which should probably be the more convenient side of this package,rdiris the more powerful and useful component here.
It allows you to run a regex filter to restrict the names returned by 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).Thepdirfunction is itself dependent onrdirin its internal usage.rdir ->
* Does not pretty print by default and returns a list which can be assigned to another object.
* To enable pretty printing, you have to disable return, by providing ret = False as an additional parameter.Notespdiris essentially a wrapper onrdir, which in itself is a wrapper around the Pythondirfunction.The code for this tool is availablehere.Would be glad to see anyone interested in contributing.You can email me or leave an issue on github suggesting improvements.