Hi all,
>From the google search, it seems its not possible to do the following.
>>class Test1(object):
.... __slots__ = ['a']
....
>>class Test2(object):
.... __slots__ = ['b']
....
>>class Test3(Test1,Test2):
.... __slots__ = ['c']
....
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Error when calling the metaclass bases
multiple bases have instance lay-out conflict
I just want to make sure that I am using only the attributes a,b and c
from the instances of Test3 . Is there any other hack that could be
done.
--
Suresh 5 3994
On 14 Dec 2006 05:23:33 -0800, jm*******@no.spam.gmail.com
<jm*******@gmail.comwrote:
Hi all,
From the google search, it seems its not possible to do the following.
>class Test1(object):
... __slots__ = ['a']
...
>class Test2(object):
... __slots__ = ['b']
...
>class Test3(Test1,Test2):
... __slots__ = ['c']
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Error when calling the metaclass bases
multiple bases have instance lay-out conflict
I just want to make sure that I am using only the attributes a,b and c
from the instances of Test3 . Is there any other hack that could be
done.
Difficulty with subclassing is the price you pay for abusing slots.
Slots are intended as a performance tweak only, to minimise the memory
footprint of classes of which you are going to have a great number of
instances.
In short - don't do that.
--
Cheers,
Simon B si***@brunningonline.net http://www.brunningonline.net/simon/blog/
Simon Brunning wrote:
On 14 Dec 2006 05:23:33 -0800, jm*******@no.spam.gmail.com
<jm*******@gmail.comwrote:
Hi all,
>From the google search, it seems its not possible to do the following.
>>class Test1(object):
... __slots__ = ['a']
...
>>class Test2(object):
... __slots__ = ['b']
...
>>class Test3(Test1,Test2):
... __slots__ = ['c']
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Error when calling the metaclass bases
multiple bases have instance lay-out conflict
I just want to make sure that I am using only the attributes a,b and c
from the instances of Test3 . Is there any other hack that could be
done.
Difficulty with subclassing is the price you pay for abusing slots.
Slots are intended as a performance tweak only, to minimise the memory
footprint of classes of which you are going to have a great number of
instances.
In short - don't do that.
OK. But is there any other way to do what __slots__ does as a 'side
effect' i.e. forcing me to think about the list of attributes my class
is going to have upfront and raising error whenever I violate it. IMHO
this is a very good thing to have even if one does not care about
memory.
--
Suresh
>
--
Cheers,
Simon B si***@brunningonline.net http://www.brunningonline.net/simon/blog/ jm*******@no.spam.gmail.com wrote:
OK. But is there any other way to do what __slots__ does as a 'side
effect' i.e. forcing me to think about the list of attributes my class
is going to have upfront and raising error whenever I violate it. IMHO
this is a very good thing to have even if one does not care about
memory.
See http://aspn.activestate.com/ASPN/Coo.../Recipe/252158 (how
to freeze Python classes)
Michele Simionato
Simon Brunning wrote:
Difficulty with subclassing is the price you pay for abusing slots.
Although you could have the same difficulty even
if you weren't abusing them.
It's just a limitation of the implementation.
The use of __slots__ forces a particular layout
im memory, and you can only do that for one
base class at a time.
--
Greg jm*******@no.spam.gmail.com wrote:
Simon Brunning wrote:
>On 14 Dec 2006 05:23:33 -0800, jm*******@no.spam.gmail.com <jm*******@gmail.comwrote:
>>Hi all, From the google search, it seems its not possible to do the following.
>class Test1(object): ... __slots__ = ['a'] ... >class Test2(object): ... __slots__ = ['b'] ... >class Test3(Test1,Test2): ... __slots__ = ['c'] ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: Error when calling the metaclass bases multiple bases have instance lay-out conflict
I just want to make sure that I am using only the attributes a,b and c from the instances of Test3 . Is there any other hack that could be done.
Difficulty with subclassing is the price you pay for abusing slots. Slots are intended as a performance tweak only, to minimise the memory footprint of classes of which you are going to have a great number of instances.
In short - don't do that.
OK. But is there any other way to do what __slots__ does as a 'side
effect' i.e. forcing me to think about the list of attributes my class
is going to have upfront and raising error whenever I violate it. IMHO
this is a very good thing to have even if one does not care about
memory.
--
Suresh
>-- Cheers, Simon B si***@brunningonline.net http://www.brunningonline.net/simon/blog/
Sounds a lot like you are coming from another programming language
and are trying to make Python act like it did. Hey I did the same
thing when I first took up Python as a language. Python is not Java
(or any other language that puts you in a straight jacket). IMHO if
you embrace the dynacism of Python and you will be much happier
writing code in it. Don't worry if someone will try to assign to
some attribute in your class that "is illegal". They may be doing
if for some reason you can't fathom at the outset.
-Larry This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nick Jacobson |
last post by:
The __slots__ attribute of new-style classes can reduce memory usage
when there are millions of instantiations of a class.
So would a __slots__ attribute for functions/methods have a similar...
|
by: Jonathan Brandmeyer |
last post by:
I am attempting to create a class that inherits from a PyGTK class and a
Boost.Python-based class. When the interpreter executes code like:
class Myclass( gtk.some_class, my_boost_python_class):...
|
by: Nitin Shukla |
last post by:
Hello,
Can anyone tell why am I getting this error and how to work around this
problem.
>>> class Klass(object):
.... __slots__ = ( 'x' )
....
>>> class Klass1(object):
.... __slots__ =...
|
by: Matthew Louden |
last post by:
I want to know why C# doesnt support multiple inheritance? But why we can
inherit multiple interfaces instead? I know this is the rule, but I dont
understand why. Can anyone give me some concrete...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |