I'm implementing a python class that contains a 2d numpy array (self.data
) that I have set up for column access with a string key.
The keys are contained in a dict that maps names to column indices (e.g., self.coldict={'col0':0,...,'colN':N}
), and I've defined
def __getitem__(self,key):
if isinstance(key,str):
return self.data[:,self.coldict[key]]
elif isinstance(key,int):
return self.data[:,key]
This works as intended for column retrieval.
I'd like to be able to use tab complete for the key so that I can type
myObject['c+TAB
during an iPython session to get completion options.
I think a solution should rely on readline or prompt_toolkit, but it's not clear to me how to implement a completer function without overriding the already-active functionality in iPython.
Any help is much appreciated. Thanks!