I
Ismael Herrera
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.mimetools
urllib2.AbstractDigestAuthHandler urllib2.__delattr__
urllib2.mimetypes
urllib2.AbstractHTTPHandler urllib2.__dict__
urllib2.noheaders
urllib2.BaseHandler urllib2.__doc__
urllib2.os
urllib2.CacheFTPHandler urllib2.__file__
urllib2.parse_http_list
urllib2.CustomProxy urllib2.__getattribute__
urllib2.parse_keqv_list
<skip>..
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[ort]/path') --> 'host[ort]', '/path'
splitpasswd <f> : splitpasswd('userasswd') -> 'user', 'passwd'
splitport <f> : splitport('hostort') --> 'host', 'port'
splitquery <f> : splitquery('/path?query') --> '/path', 'query'
splittype <f> : splittype('typepaquestring') --> 'type', 'opaquestring'
splituser <f> : splituser('user[asswd]@host[ort]') --> 'user[asswd]',
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()
iter.sort()
for x in iter:
attr = getattr(name,x)
try: ## can be better with hasattr() builtin
doc = str(attr.__doc__)
except:
print ' %s %s' % (x,attr)
continue
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'
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.mimetools
urllib2.AbstractDigestAuthHandler urllib2.__delattr__
urllib2.mimetypes
urllib2.AbstractHTTPHandler urllib2.__dict__
urllib2.noheaders
urllib2.BaseHandler urllib2.__doc__
urllib2.os
urllib2.CacheFTPHandler urllib2.__file__
urllib2.parse_http_list
urllib2.CustomProxy urllib2.__getattribute__
urllib2.parse_keqv_list
<skip>..
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[ort]/path') --> 'host[ort]', '/path'
splitpasswd <f> : splitpasswd('userasswd') -> 'user', 'passwd'
splitport <f> : splitport('hostort') --> 'host', 'port'
splitquery <f> : splitquery('/path?query') --> '/path', 'query'
splittype <f> : splittype('typepaquestring') --> 'type', 'opaquestring'
splituser <f> : splituser('user[asswd]@host[ort]') --> 'user[asswd]',
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()
iter.sort()
for x in iter:
attr = getattr(name,x)
try: ## can be better with hasattr() builtin
doc = str(attr.__doc__)
except:
print ' %s %s' % (x,attr)
continue
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'