[SciPy-dev] adding new attribute to data type objects

Travis Oliphant oliphant at ee.byu.edu
Tue Nov 1 14:23:12 CST 2005

Christopher Hanley wrote:

>Hi Travis,
>In numarray a user is able to say the following in order to get the size
>of a data type in bytes:
>This is a useful feature that is used in multiple locations within the
>Records implementation.  I cannot find an equally simple functionality
>within newcore.  There are obvious work arounds that I could use but I
>fear that they aren't as efficient as having a simple attribute on the
>data type object.  Is there some easy way of adding a similar feature to 

Yes, I've thought about this.  The problem is I don't know exactly how 
to add a class attribute to a built in type object.   I suppose, this 
could be done using metaclasses.  But, I think it would just be easier 
to build a bytes dictionary so that scipy.bytes[int32] gave the 
information you wanted.  Of course this example is rather pointless 
because the number of bytes is just the number of bits divided by 8.

The information is there right now in the typeinfo dictionary in the 
multiarray module (it's just not well exposed). 


More information about the Scipy-dev mailing list