Skip to content

Instantly share code, notes, and snippets.

@olemb
Created July 1, 2013 15:14
Show Gist options
  • Save olemb/5901717 to your computer and use it in GitHub Desktop.
Save olemb/5901717 to your computer and use it in GitHub Desktop.
A version of dir() which lists only public attributes.
"""
This goes in the PYTHONSTARTUP file.
Example:
>>> pubdir([])
['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
"""
__pubdir_no_arg = []
def pubdir(obj=__pubdir_no_arg):
if obj is __pubdir_no_arg:
attributes = dir()
else:
attributes = dir(obj)
return [a for a in attributes if not a.startswith('_')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment