[Python-Dev] a nicer looking dir()

Mike Klaas mike.klaas at gmail.com
Thu Feb 19 02:53:52 CET 2009


Someone has implemented a version of dir() which is much nicer for  
human consumption.  The difference is striking enough that I thought  
it would be bringing to python-dev's attention.

http://github.com/inky/see/tree/master

 >>> pencil_case = []
 >>> dir(pencil_case)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',  
'__delsli ce__', '__doc__', '__eq__', '__ge__', '__getattribute__',  
'__getitem__', '__gets lice__', '__gt__', '__hash__', '__iadd__',  
'__imul__', '__init__', '__iter__', ' __le__', '__len__', '__lt__',  
'__mul__', '__ne__', '__new__', '__reduce__', '__r educe_ex__',  
'__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__ ',  
'__setslice__', '__str__', 'append', 'count', 'extend', 'index',  
'insert', 'p op', 'remove', 'reverse', 'sort']
 >>> see(pencil_case)

  ? [] for in + * += *= < <= == != > >= len() .append() .count()

   .extend() .index() .insert() .pop() .remove() .reverse() .sort()

I'm not sure that this type of functionality merits a new built-in,  
but it might be useful as part of help()'s output.

-Mike


More information about the Python-Dev mailing list