473,320 Members | 1,832 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,320 software developers and data experts.

Multi Heritage with slots

Hye,

I'm developing a little app, and I want to make multi heritage.
My problem is that my both parent do have __slots__ define.

So I've got something like:

class foo(object):
__slots__ = ['a', 'b']
pass

class foo2(object):
__slots__ = ['c', 'd']
pass

class crash(foo, foo2):
pass

If you write only that in a sample file or in python console (as I
did), python refuse to load the module and report something like:

Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: Error when calling the metaclass bases
multiple bases have instance lay-out conflict

Do you know why it append? And how could I make this work?

Sep 5 '07 #1
5 2440
On Wed, 05 Sep 2007 11:01:56 +0200, Alexandre Badez
<al*************@gmail.comwrote:
Hye,

I'm developing a little app, and I want to make multi heritage.
My problem is that my both parent do have __slots__ define.

So I've got something like:

class foo(object):
__slots__ = ['a', 'b']
pass

class foo2(object):
__slots__ = ['c', 'd']
pass

class crash(foo, foo2):
pass

If you write only that in a sample file or in python console (as I
did), python refuse to load the module and report something like:

Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: Error when calling the metaclass bases
multiple bases have instance lay-out conflict

Do you know why it append? And how could I make this work?
See http://mail.python.org/pipermail/pyt...er/418768.html

Basically, the general advice you're likely to get here is: don't use
__slots__, or at least don't use __slots__ with inheritance.

BTW, what are you trying to do? Is it really a memory footprint
optimization, which is the intended use case for __slots__, or are you
just doing Java in Python?
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
Sep 5 '07 #2
On Sep 5, 12:42 pm, "Eric Brunel" <see.signat...@no.spamwrote:
Seehttp://mail.python.org/pipermail/python-list/2006-December/418768.html

Basically, the general advice you're likely to get here is: don't use
__slots__, or at least don't use __slots__ with inheritance.

BTW, what are you trying to do? Is it really a memory footprint
optimization, which is the intended use case for __slots__, or are you
just doing Java in Python?
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
Thanks for your answer.
I use __slots__ not for memory optimization nor doing java.
I use __slots__ because my class are used by other lib, and in the
past, some of them misspell some attributes and involved a very
annoying comportment of the global application.
So the objective is only to prevent unwanted dynamism (but not in all
the application, just some class).

PS: I very like your signature ;)

Sep 5 '07 #3
On 9/5/07, Alexandre Badez <al*************@gmail.comwrote:
I use __slots__ not for memory optimization nor doing java.
I use __slots__ because my class are used by other lib, and in the
past, some of them misspell some attributes and involved a very
annoying comportment of the global application.
So the objective is only to prevent unwanted dynamism (but not in all
the application, just some class).
Using slots to prevent the creation of new properties is what Eric
*means* by "doing java". You're trying to write Java style code in
Python, and it's not going to be pretty. Slots are not intended for
this purpose, and they aren't very good for it.

--
Cheers,
Simon B.
si***@brunningonline.net
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues
Sep 5 '07 #4
On Sep 5, 2:52 pm, "Simon Brunning" <si...@brunningonline.netwrote:
On 9/5/07, Alexandre Badez <alexandre.ba...@gmail.comwrote:
I use __slots__ not for memory optimization nor doing java.
I use __slots__ because my class are used by other lib, and in the
past, some of them misspell some attributes and involved a very
annoying comportment of the global application.
So the objective is only to prevent unwanted dynamism (but not in all
the application, just some class).

Using slots to prevent the creation of new properties is what Eric
*means* by "doing java". You're trying to write Java style code in
Python, and it's not going to be pretty. Slots are not intended for
this purpose, and they aren't very good for it.
Right, and this the way to do what the original poster wants:

http://aspn.activestate.com/ASPN/Coo.../Recipe/252158

Michele Simionato

Sep 5 '07 #5
On Sep 5, 2:56 pm, Michele Simionato <michele.simion...@gmail.com>
wrote:
On Sep 5, 2:52 pm, "Simon Brunning" <si...@brunningonline.netwrote:
On 9/5/07, Alexandre Badez <alexandre.ba...@gmail.comwrote:
I use __slots__ not for memory optimization nor doing java.
I use __slots__ because my class are used by other lib, and in the
past, some of them misspell some attributes and involved a very
annoying comportment of the global application.
So the objective is only to prevent unwanted dynamism (but not in all
the application, just some class).
Using slots to prevent the creation of new properties is what Eric
*means* by "doing java". You're trying to write Java style code in
Python, and it's not going to be pretty. Slots are not intended for
this purpose, and they aren't very good for it.

Right, and this the way to do what the original poster wants:

http://aspn.activestate.com/ASPN/Coo.../Recipe/252158

Michele Simionato
Thanks every body for your remarks.
I still have a lot to learn in python...

Sep 5 '07 #6

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

Similar topics

7
by: Boris Boutillier | last post by:
Hi all, Of what I heard Python 2.3 now allow creation of new types in C with slots. Is there somewhere some documentation on this, or at least an example ? Thanks a lot Boris
1
by: Frank Bossy | last post by:
Dear group :) I don't quite understand the meaning of this paragraph in the qt docu (http://doc.trolltech.com/3.1/threads.html): ***SNIP The Signals and Slots mechanism can be used in...
2
by: tin gherdanarra | last post by:
Dear pythonista, what is a "slot" in python? I stumbled over it in several meta-reflection discussions and hard-core developer talk, but found no mention of it in the language reference. ...
27
by: Bernard Bourée | last post by:
Is there a way to overpass the impossibility of VN.NET to accept the multi heritage, that is to allow a class to inherit from TWO mother classes ? -- Bernard Bourée bernard@bouree.net
5
by: Christian Bruckhoff | last post by:
Hi. I got a problem with Signals and Slots of QT. The program i am speaking of u can find here: http://www.uni-koblenz.de/~brchrist/address/ If u look at gui.cpp u find a connect command at...
0
by: ArizonaState | last post by:
I would like to populate a listview with fields from a table, but with data that does not exist yet... Here is an example... 1. DropDown list allows for selecting a Location 2. Selected...
0
by: Brian Vanderburg II | last post by:
I don't know if any such support is already built in, so I ended up making my own simple signals/slots like mechanism. If anyone is interested then here it is, along with a simple test. It can...
1
by: Scott SA | last post by:
On 5/1/08, Brian Vanderburg II (BrianVanderburg2@aim.com) wrote: Did you review this? <http://pydispatcher.sourceforge.net/> from what I understand is originally based upon this:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.