ipython instrospection like editor,ide

Ismael Herrera ismaelherreragasser at hotmail.com
Thu Sep 30 06:09:38 CEST 2004

 Hi,i wonder if there is an editor or ide that has similar dinamic
instrospection features as ipython? ,since i have failed to find one, i
spend more time coding in ipython than in my editor. 

  Well the feature i need the most is tab introspection since python has so
many libraries and functions that is imposible to remember all of them.For
example when i type urllib2.<tab> i get:

urllib2.AbstractBasicAuthHandler         urllib2.__class__                       
urllib2.AbstractDigestAuthHandler        urllib2.__delattr__                     
urllib2.AbstractHTTPHandler              urllib2.__dict__                        
urllib2.BaseHandler                      urllib2.__doc__                         
urllib2.CacheFTPHandler                  urllib2.__file__                        
urllib2.CustomProxy                      urllib2.__getattribute__                


I also made a function that gives me a quickly overview of an objects,for
example when i type h(urllib2) i get :
 AbstractBasicAuthHandler <c> : Non
 AbstractDigestAuthHandler <c> : Non
 AbstractHTTPHandler <c> : Non
 BaseHandler <c> : Non
 CacheFTPHandler <c> : Non
 CustomProxy <c> : Non
 CustomProxyHandler <c> : Non
 socket <m> : This module provides socket operations and some related 
 splitattr <f> : splitattr('/path;attr1=value1;attr2=value2;...') ->
 splitgophertype <f> : splitgophertype('/Xselector') --> 'X', 'selector'
 splithost <f> : splithost('//host[:port]/path') --> 'host[:port]', '/path'
 splitpasswd <f> : splitpasswd('user:passwd') -> 'user', 'passwd'
 splitport <f> : splitport('host:port') --> 'host', 'port'
 splitquery <f> : splitquery('/path?query') --> '/path', 'query'
 splittype <f> : splittype('type:opaquestring') --> 'type', 'opaquestring'
 splituser <f> : splituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 
 unquote <f> : unquote('abc%20def') -> 'abc def'
 unwrap <f> : unwrap('<URL:type://host/path>') --> 'type://host/path'
 url2pathname <f> : Non
 urlopen <f> : Non
 urlparse <m>  

Well,i would like similar functionality in the enviroment that i am coding
in, i hate having to go to the interactive shell every 7 seconds to type
'h(<class name>)' for example.

The code for my help function (is sucky since i have had so much trouble
finding the types of some objects and doesnt work for some modules):

import sgmllib
import types

def h(name,display='all',allow_herencia=False):
    '''name-> any object name that is not an instance(module,attr,func)
       display-> all | m | f | c | a  ie : m = module
       allow_Herencia True | False
       Display object's information for a quick overview 
    if allow_herencia == True : iter = dir(name)     
    else : 
                iter = name.__dict__.keys() 
    for x in iter:
       attr = getattr(name,x)
       try:  ## can be better with hasattr() builtin  
        doc = str(attr.__doc__)
        print ' %s %s' % (x,attr)
       else :
        limit = doc.find('\n')
        doc = doc[:limit]
        membertype = __gettype(attr)
        if display is membertype or display is 'all': print ' %s <%s> : %s'                                                                
% (x,membertype,doc)

def __gettype(attr):
        ## needs reworking
    t = type(attr)
    #print t
    if t is types.ModuleType : return 'm'
    elif t is type(str.isupper) or\
         t is types.BuiltinFunctionType or\
         t is types.FunctionType or\
         t is types.UnboundMethodType or\
         t is '<type \'instancemethod\'>' : 
            return 'f'
    elif t is type(str.__eq__) : return 'w' #wraper
    elif t is types.TypeType or t is type(sgmllib.SGMLParser): return 'c'
    else: return 'a'

More information about the Python-list mailing list