how to add class attributes in __new__

J

jeremito

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
 
A

aspineux

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top