473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to add class attributes in __new__

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

Feb 1 '07 #1
2 1512
jeremito a écrit :
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?
http://www.python.org/download/relea...intro/#__new__
Feb 1 '07 #2
On 1 fév, 17:50, "jeremito" <jerem...@gmail.comwrote:
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

Feb 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Fernando Rodriguez | last post by:
Hi, I have a base class with a 'sanity-check' method. This method should iterate through all the methods and check if they are all 'thunks' (zero parameter functions, well actually, 1 parameter:...
3
by: daishi | last post by:
Hi, I am wondering if someone could help me understand some of the details of using metaclasses. I am trying to use metaclasses to auto-generate some attributes and methods in a class...
14
by: Sridhar R | last post by:
Consider the code below, class Base(object): pass class Derived(object): def __new__(cls, *args, **kwds): # some_factory returns an instance of Base # and I have to derive from this...
50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
0
by: Carlos Ribeiro | last post by:
I thought about this problem over the weekend, after long hours of hacking some metaclasses to allow me to express some real case data structures as Python classes. I think that this is something...
8
by: Mark English | last post by:
I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window...
10
by: David Hirschfield | last post by:
Here's a strange concept that I don't really know how to implement, but I suspect can be implemented via descriptors or metaclasses somehow: I want a class that, when instantiated, only defines...
4
by: rzed | last post by:
I'm confused (not for the first time). I create these classes: class T(object): def __new__(self): self.a = 1 class X(T): def __init__(self):
0
by: Terry Reedy | last post by:
Prashant Saxena wrote: A property with a working get and set that raises an exception. Don't know. I believe this is what slots is for.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.