>>>>> Nick <nleio...@gmail.com> (N) wrote: >N> this is the new oop version, its pretty messy currently, and i do >N> understand it is a simple routine, but i'm using it as an exercise to >N> learn oop python...
>N> first the (current) traceback: >N> [:~/python]$ python oop_covariance.py b2ar_all_test b2ar_all_test >N> <Eigen.Eigen_vect instance at 0x7fa26c404ab8> >N> <Eigen.Eigen_vect instance at 0x7fa26c404ab8> >N> Traceback (most recent call last): >N> File "oop_covariance.py", line 24, in <module> >N> cov = set1.covariance(set2, Eigen_vect.dot) >N> File "/home/nleioatts/python/Eigen.py", line 66, in covariance >N> print self.vectors[i][i] >N> AttributeError: Eigen_vect instance has no attribute '__getitem__' self.vectors is a list of Eigen_vect objects. So self.vectors[i] is an Eigen_vect object. Now you do a subscript on this Eigen_vect object but you have not defined what that means. Presumably you want it to do the subscript on the self.e_vect in the Eigen_vect instance. Therefore you have to define the __getitem__ method in the Eigen_vect class. class Eigen_vect: def __init__(self, e_val, e_vect): self.e_val = e_val self.e_vect = e_vect def length(self): return len(self.e_vect) def __getitem__(self, indx): return self.e_vect[indx] I hope I did not make a mistake, I didn't check it because I don't want to make test input files. -- Piet van Oostrum <p...@cs.uu.nl> URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list