[IPython-User] Question about object introspection

Matthias BUSSONNIER bussonniermatthias@gmail....
Sat Sep 22 07:47:56 CDT 2012


Le 22 sept. 2012 à 14:42, klo uo a écrit :

> I'll try to explain through example:
> 
> ========================================
> In [1]: from lxml import etree
> 
> In [2]: tree = etree.fromstring('<foo><bar></bar></foo>')
> In [3]: xp = tree.xpath('/foo/bar')
> ========================================
> 
> Now "xp" is a list of objects, in above example list of just one object:
> 
> [<Element bar at 0x1aa4aa8>]
> 
> So if I want to access variable "xp", I must access list item, and IPython treats it as a list without exposing underlying object.
> 
> As in:
> 
> In [4]: xp[0].<tab>
> 
> it won't let me inspect the object, while if I type:
> 
> In [5]: xp0 = xp[0]
> In [6]: xp0.<tab>

This is the greedy completer, it is an option, because [] can actually be a methods that have side effects… 
Introspecting would trigger this methods, like querying over the web, or change the state of an oscilloscope…

So it is disabled by default.

You can opt-in with --IPcompleter.greedy=True 
or 
%config IPconmpleter.greedy=True

and do 
'mystring'.u<tab>
to completer to uppercase().

-- 
Matthias

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20120922/b47ed14c/attachment.html 


More information about the IPython-User mailing list