[IPython-user] Auto-Completion incomplete?

Fernando Perez Fernando.Perez at colorado.edu
Fri Oct 15 16:20:05 CDT 2004


Norbert Nemec schrieb:
> Hi there,
> 
> I'm rather new to python, so there might really be a simple answer to this 
> that I just don't see. In any case: I would assume that other newbies have to 
> struggle just the same:
> 
> Using ipython with scipy installed, I do the following:
> 
> --------------------------------
> In [1]: from scipy import *
> 
> In [2]: a=zeros(3)
> 
> In [3]: a.<tab pressed to get completion>
> a.__copy__	a.copy		a.savespace	a.tostring
> a.__deepcopy__	a.iscontiguous	a.spacesaver	a.typecode
> a.astype	a.itemsize	a.tolist
> a.byteswapped	a.resize	a.toscalar
> 
> In [3]: a.shape
> Out[3]: (3,)
> 
> In [4]:
> --------------------------------
> 
> My question: why doesn't 'shape' appear in the list of completions?
> 
> What would have been the correct place to look it up? I was looking for a way 
> to retrieve the shape of an array, but I did not find it anywhere until I 
> stumbled over it in some example code.

It's not a bug in ipython, it has to do with how Numeric arrays are implemented:

In [1]: a=zeros(3)

In [2]: dir(a)
Out[2]:
['__copy__',
  '__deepcopy__',
  'astype',
  'byteswapped',
  'copy',
  'iscontiguous',
  'itemsize',
  'resize',
  'savespace',
  'spacesaver',
  'tolist',
  'toscalar',
  'tostring',
  'typecode']

In [3]: getattr(a,'shape')
Out[3]: (3,)

As you can see, 'shape' is NOT listed in the object's dir(), but it IS 
returned by a getattr() call.  So there is no way that any tab-completion 
library will ever see it, since you can only find it by explicitly requesting 
it.  I suspect this behaviour comes from the fact that Numeric arrays are 
mostly implemented in C with a bunch of tricks, so they bypass some of the 
more 'normal' python mechanisms.

Cheers,

f




More information about the IPython-user mailing list