This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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__ | |