how to add class attributes in __new__

aspineux aspineux at gmail.com
Thu Feb 1 19:19:47 EST 2007


On 1 fév, 17:50, "jeremito" <jerem... at gmail.com> wrote:
> I am subclassing the array class and have __new__ to initialize and
> create my class.  In that class I create not only do I create an array
> object, but I also create some other data in __new__ I want to have
> access to outside of __new__.  I tried
>
> self.mydata = mydata
>
> but that didn't work.
>
> Can someone point me in the right direction?
> Thanks,
> Jeremy

self ? in __new__ ?

What about with this ?

    def __new__(cls, *args, **kw):
        newobj=object.__new__(cls)
        newobj.foo='bar'
        return newobj




More information about the Python-list mailing list