Extending the interactive mode [not really an ANN :) ]
Tjabo Kloppenburg
Tjabo.Kloppenburg at unix-ag.org
Sat Mar 23 06:56:04 EST 2002
hi,
I use python22 and dreamt about a comfortable way of using the interactive
mode to find information about what methods/functions a class/module provides
and what the helpful __doc__ string says (keeping ri [ruby] in my mind).
The annoying way to do this in python interactive mode -- with lots of key
strokes and many risks of mistypnig -- is to type:
print mod.__doc__ +Enter
print dir(mod) +Enter
So I finally wrote a very small function to be loaded from PYTHONSTARTUP when
using interactive mode. It is self explanatory and gives you information
about a module by typing "info(mod)". Fairly easy...
The mighty source:
# Author: tk at bitsex.de aka tapo in #python
#
# this is a small function you can load when starting python interactivly:
# - put it into ~/.pythonstartup
# - do an "export PYTHONSTARTUP=$PYTHONSTARTUP:~/.pythonstartup
# - restart "python" or "python22" without arguments
# - now type: "info(info)" +enter :-)
def info(mod):
"\nThis is a small function to show some info about a module.\nUsage in
python interactive mode:\n import sys\n info(sys)"
print "Info for module/class '%s':" % (mod.__name__)
print mod.__doc__
print "\nList of methods:"
print dir(mod)
Always on a mission to save the world,
tk. :-)
--
+ 7jaB0 Kl0ppE|\|8\_/R6 + 7|<@B175Ex.[}E + [}3,3n +
More information about the Python-list
mailing list