Skip to content

Instantly share code, notes, and snippets.

@voyeg3r
Created March 6, 2010 12:03
Show Gist options
  • Select an option

  • Save voyeg3r/323655 to your computer and use it in GitHub Desktop.

Select an option

Save voyeg3r/323655 to your computer and use it in GitHub Desktop.
apihelper python
#!/usr/bin/env python
# # -*- coding: UTF-8 -*-
# Criado em:Sáb 06/Mar/2010 hs 08:09
# Last Change: Sáb 06 Mar 2010 08:40:18 BRT
# vim:ft=python:nolist:nu:
# Instituicao: cpqt
# Proposito do script: apihelper - acesso à documentação dos módulos
# Autor: Sérgio Luiz Araújo Silva
# site: http://vivaotux.blogspot.com
# Este código foi copiado do livro "Mergulhando no Python",
# o original em inglês chama-se "Dive in python"
# o código abaixo pode ser visto na página 31 da versão em português
# para usar faça algo como
# import math
# info(math)
def info(object, spacing=10, collapse=1):
"""Exibe métodos e doc strings,
usa módulos, classes, listas, dicionários ou strings."""
methodList = [ method for method in dir(object) if callable(getattr(object, method)) ]
processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
print "\n".join(["%s %s" % (method.ljust(spacing),
processFunc(str(getattr(object, method).__doc__))) for method in methodList])
if __name__ == "__main__":
print info.__doc__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment