can't set attributes of built-in/extension type

7stud bbxx789_05ss at yahoo.com
Thu Feb 21 13:27:26 EST 2008


On Feb 21, 11:19 am, Neal Becker <ndbeck... at gmail.com> wrote:
> I'm working on a simple extension.  Following the classic 'noddy' example.
>
> In [15]: cmplx_int32
> Out[15]: <type 'numpy.cmplx_int32'>
>
> Now I want to add an attribute to this type.  More precisely, I want a class
> attribute.
>
> cmplx_int32.test = 0
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
>
> /home/nbecker/numpy/<ipython console> in <module>()
>
> TypeError: can't set attributes of built-in/extension
> type 'numpy.cmplx_int32'
>
> What am I missing?


class Dog(object):
    def __setattr__(self, attr, val):
        print "TypeError: can't set attributes of built-in/extension"
        print "type 'Dog.cmplx_int32'"

d = Dog()
d.test = 0

--output:--
TypeError: can't set attributes of built-in/extension
type 'Dog.cmplx_int32'



More information about the Python-list mailing list