hughesadam_87 54 Junior Poster


I have been subclassing namedtuple to handle my custom data type:

fields=['Query', 'u1', 'Accession]

Old = namedtuple('Old', fields, verbose=False)

class New(Old):
    def __repr__(self):
        return 'Overwriting works nicely'

print p
>>> 'Overwriting works nicely'

What I want to do is to add the behavior that some of my fields must be a certain type. For example, 'Query' must be a string. If the user does something like:


I want it to raise an error. I tried overwriting the set_item attribute, but to no avail. Is there anyway to make the named tuple aware of what data type each field ought to have outright in the declaration? SOmething like:

fields=[str('Query'), int('u1'), int('Accession')]

Which doens't work. Thanks.

hughesadam_87 54 Junior Poster

Hey everyone.

I have a matrix of matricies. Basically, I have a 3 dimensional matrix object which stores i 2-d arrays. For example:

A= M[1,:,:] = (j, k)
B= M[2, :, :] = (j', k')

Now, what is want to do is actually do the entire product (ABC...); however, I don't really have a good way to store these variables dynamically. For example, if in one run I have 8 2-d arrays, and in the next run I have 6 2-d arrays, I have no idea how to dynamically change a product from an 8-element product to a 6-element product.

Let me know if I've made my problem clear.