Q:

In Python, how can I append an ndarray to self in a function

I have several text files containing signals.  The time (t) is common to the two files, but each file contains different signals (a, b, c, d), so I combine everything.  I'd like to use this as the basis for a class. 
import numpy as np
from numpy.lib.recfunctions import join_by
class MyClass():
    def __init__(self):
        f1 = open('file1', 'r')
        f2 = open('file2', 'r')
        data1 =  np.loadtxt(f1, dtype={'names': ('t', 'a', 'b'), 
            'formats':('e5', 'e5', 'e5')})
        data2 =  np.loadtxt(f2, dtype={'names': ('t', 'c', 'd'), 
            'formats':('e5', 'e5', 'e5')})  
        f1.close() 
        f2.close()
        data12 = join_by('t', data1, data2, jointype='outer')
        print 'Type: ', type(data12)
        print 't: ', data12['t']
        self = np.append(self, data12)

When I run this, I get:
In [1]: myData = MyClass()
Type:  <class 'numpy.ma.core.MaskedArray'>
t:  [0.0 0.1 0.2 0.3 0.4]

In [2]: myData['t']
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-192-89155a5d901a> in <module>()
----> 1 myData['t']

TypeError: __getitem__() takes exactly 3 arguments (2 given)

Is there a way I can access 't' as myData['t'] and similarly myData['a'] and all the other signals?  I can do it as myData.data['t'], but that's redundant.  I'd be equally happy with changing things so I have myData.t, myData.a, etc.

A:

MyClass.__getitem__ can delegate to the ndarray's __getitem__ method.
class MyClass(object):
    def __init__(self):
        ...
        self._data = data12

    def __getitem__(self, obj):
        return self._data.__getitem__(obj)

