Re: Why cannot I use __slots__ and weakrefs together?

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 11:53:42 +0200, Christian Heimes wrote: >> Why does weakref hate my Eggs class? > > Weakref needs some place to store reference information. It works if you > add "__weakref__" to your slots: > > class Eggs: > __slots__ = ['spanis

Re: Why cannot I use __slots__ and weakrefs together?

2018-05-26 Thread Gregory Ewing
Steven D'Aprano wrote: TypeError: cannot create weak reference to 'Eggs' object Why does weakref hate my Eggs class? Classes with __slots__ aren't automatically given a __weakref__ slot, to save memory I suppose. But you can give it one explicitly: >>>

Re: Why cannot I use __slots__ and weakrefs together?

2018-05-26 Thread Christian Heimes
On 2018-05-26 11:17, Steven D'Aprano wrote: > Here is my code: > > > > cut here %< > > import weakref > d = weakref.WeakValueDictionary() > > class Spam: > pass > > class Eggs: > __slots__ = ['spanish_inquisition'

Why cannot I use __slots__ and weakrefs together?

2018-05-26 Thread Steven D'Aprano
Here is my code: cut here %< import weakref d = weakref.WeakValueDictionary() class Spam: pass class Eggs: __slots__ = ['spanish_inquisition'] d['a'] = Spam() # Okay. d['b'] = Eggs() # Nobody will expect what happens next! cut here

Re: Python3, __slots__ and serialization

2014-02-08 Thread Ned Batchelder
On 2/8/14 1:29 PM, Ned Batchelder wrote: On 2/8/14 1:06 PM, Eric Jacoboni wrote: Hi, Say i want create a class with a __slots__ tuple in order to prevent creation of new attributes from outside the class. Say i want to serialize instances of this class... With pickle, all is ok : i can dump

Re: Python3, __slots__ and serialization

2014-02-08 Thread Ned Batchelder
On 2/8/14 1:06 PM, Eric Jacoboni wrote: Hi, Say i want create a class with a __slots__ tuple in order to prevent creation of new attributes from outside the class. Say i want to serialize instances of this class... With pickle, all is ok : i can dump an object to a file, then reload it. With

Python3, __slots__ and serialization

2014-02-08 Thread Eric Jacoboni
Hi, Say i want create a class with a __slots__ tuple in order to prevent creation of new attributes from outside the class. Say i want to serialize instances of this class... With pickle, all is ok : i can dump an object to a file, then reload it. With PyYAML, i can dump an object to a file

Re: Questions on __slots__

2012-05-19 Thread Charles Hixson
On 05/19/2012 06:39 AM, Adam Tauno Williams wrote: On Fri, 2012-05-18 at 09:53 -0700, Charles Hixson wrote: Does __slots__ make access to variables more efficient? Absolutely, yes. If one uses property() to create a few read-only pseudo-variables, does that negate the

Re: Questions on __slots__

2012-05-19 Thread Adam Tauno Williams
On Fri, 2012-05-18 at 09:53 -0700, Charles Hixson wrote: > Does __slots__ make access to variables more efficient? Absolutely, yes. > If one uses property() to create a few read-only pseudo-variables, does > that negate the efficiency advantages of using __slots__? > (Someho

Questions on __slots__

2012-05-18 Thread Charles Hixson
Does __slots__ make access to variables more efficient? If one uses property() to create a few read-only pseudo-variables, does that negate the efficiency advantages of using __slots__? (Somehow I feel the documentation needs a bit of improvement.) -- Charles Hixson -- http://mail.python.org

Re: Why __slots__ slows down attribute access?

2011-08-23 Thread Adam Skutt
On Aug 23, 5:48 am, Jack wrote: > People have illusion that it is faster to visit the attribute defined > by __slots__ > .http://groups.google.com/group/comp.lang.python/msg/c4e413c3d86d80be > > That is wrong. The following tests show it is slower. No, they don't really

Re: Why __slots__ slows down attribute access?

2011-08-23 Thread John-John Tedro
On Tue, Aug 23, 2011 at 12:26 PM, Peter Otten <__pete...@web.de> wrote: > Jack wrote: > > > People have illusion that it is faster to visit the attribute defined > > by __slots__ . > > http://groups.google.com/group/comp.lang.python/msg/c4e413c3d86d80be > > &g

Re: Why __slots__ slows down attribute access?

2011-08-23 Thread Peter Otten
Jack wrote: > People have illusion that it is faster to visit the attribute defined > by __slots__ . > http://groups.google.com/group/comp.lang.python/msg/c4e413c3d86d80be > > That is wrong. The following tests show it is slower. Not so fast. Here's what I get (python2.6.4

Why __slots__ slows down attribute access?

2011-08-23 Thread Jack
People have illusion that it is faster to visit the attribute defined by __slots__ . http://groups.google.com/group/comp.lang.python/msg/c4e413c3d86d80be That is wrong. The following tests show it is slower. __slots__ are implemented at the class level by creating descriptors (Implementing

Bypassing properties on an object (also with __slots__?)

2010-02-18 Thread Andrey Fedorov
Two questions: 1 - is it documented that o.__dict__[attr] is a reliable way to bypass property methods? 2 - can one bypass a property method if the class has __slots__? Reason: I have a couple of different flavors of request objects which I need to make lazily conform to a standard interface. As

Re: Accessing __slots__ from C

2008-12-09 Thread Mike Kolbet
-- http://mail.python.org/mailman/listinfo/python-list

Re: Accessing __slots__ from C

2008-09-16 Thread Chris
Hrvoje Niksic xemacs.org> writes: ... > > You are getting that error because Carl forgot to cast the descriptor > > to the appropriate C type, in this case PyMemberDescrObject. The last > > line is also incorrect, I think. Try something like this: ... The code you gave was great, thanks! Now we

Re: Accessing __slots__ from C

2008-09-12 Thread Carl Banks
On Sep 12, 10:01 am, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Chris <[EMAIL PROTECTED]> writes: > >> descr = GetAttrString(cls,"varname"); > >> offset = descr->d_member->offset; > >> slotvar = (PyObject*)(((char*)obj)+offset) > > > Unfortunately, I am inexperienced at this kind of thing, so I was

Re: Accessing __slots__ from C

2008-09-12 Thread Hrvoje Niksic
Hrvoje Niksic <[EMAIL PROTECTED]> writes: > Chris <[EMAIL PROTECTED]> writes: > >>> descr = GetAttrString(cls,"varname"); >>> offset = descr->d_member->offset; >>> slotvar = (PyObject*)(((char*)obj)+offset) >> >> Unfortunately, I am inexperienced at this kind of thing, so I wasn't >> able to get s

Re: Accessing __slots__ from C

2008-09-12 Thread Hrvoje Niksic
Chris <[EMAIL PROTECTED]> writes: >> descr = GetAttrString(cls,"varname"); >> offset = descr->d_member->offset; >> slotvar = (PyObject*)(((char*)obj)+offset) > > Unfortunately, I am inexperienced at this kind of thing, so I wasn't > able to get something working. Maybe someone could tell me what's

Re: Accessing __slots__ from C

2008-09-12 Thread Hrvoje Niksic
Chris <[EMAIL PROTECTED]> writes: >> In my experience, as long as you're >> accessing simple slots, you should notice a difference. > > (I'm not sure what you mean by a 'simple slot'. I mean a slot defined by __slots__ = slot1, slot2, slot3, ..., with

Re: Accessing __slots__ from C

2008-09-12 Thread Chris
Hrvoje Niksic xemacs.org> writes: ... > Chris users.sourceforge.net> writes: > > >> PyObject_GetAttrString is convenient, but it creates a Python string > >> only so it can intern it (and in most cases throw away the freshly > >> created version). For maximum efficiency, pre-create the string >

Re: Accessing __slots__ from C

2008-09-12 Thread Chris
os! Maybe I should continue this thread on capi-sig? Thanks for your help, Chris class MyObject(object): __slots__ = ['attr_one'] def __init__(self,attr_one=1.0): self.attr_one = attr_one import weave def test(): x = MyObject code = """ PyObject *descr = Py

Re: Accessing __slots__ from C

2008-09-12 Thread Hrvoje Niksic
_FUNC /* declarations for DLL import/export */ #define PyMODINIT_FUNC void #endif PyMODINIT_FUNC initattr(void) { PyObject *module = Py_InitModule3("attr", attr_methods, NULL); } >>> import attr, time >>> class MyClass(object): ... __slots__ = 'abcdef', .

Re: Accessing __slots__ from C

2008-09-11 Thread Christian Heimes
Chris wrote: Ok, thanks for the confirmation. We'd been hoping to avoid creating such a struct... Don't worry, a C extension with its own struct isn't hard to write. Your C code can access the member variables w/o using any Python API. You'll get the full speed of C. :] Christian -- http:/

Re: Accessing __slots__ from C

2008-09-11 Thread Carl Banks
On Sep 10, 7:41 am, Chris <[EMAIL PROTECTED]> wrote: > Hi, > > I'd like to be able to access an attribute of a particular Python > object as fast as possible from some C code. > > I wondered if using __slots__ to store the attribute would allow me to > do this in

Re: Accessing __slots__ from C

2008-09-11 Thread Chris
Hrvoje Niksic xemacs.org> writes: ... > [ You can use the capi-sig for questions like this; see > http://mail.python.org/mailman/listinfo/capi-sig ] Thanks, I had no idea about that. > PyObject_GetAttrString is convenient, but it creates a Python string > only so it can intern it (and in most

Re: Accessing __slots__ from C

2008-09-11 Thread Chris
Christian Heimes cheimes.de> writes: ... > You can use slots to increase the performance but it doesn't work > like you think. If you need it *really* fast than write a C > Extension, store the data in a C struct and access the data via > PyMemberDef. Ok, thanks for the confirmation. We'd been ho

Re: Accessing __slots__ from C

2008-09-11 Thread Hrvoje Niksic
[ You can use the capi-sig for questions like this; see http://mail.python.org/mailman/listinfo/capi-sig ] Chris <[EMAIL PROTECTED]> writes: > I'd like to be able to access an attribute of a particular Python > object as fast as possible from some C code. > > I wondere

Re: Accessing __slots__ from C

2008-09-10 Thread Christian Heimes
Chris wrote: Hi, I'd like to be able to access an attribute of a particular Python object as fast as possible from some C code. I wondered if using __slots__ to store the attribute would allow me to do this in a faster way. The reason I'd like to do this is because I need to

Accessing __slots__ from C

2008-09-10 Thread Chris
Hi, I'd like to be able to access an attribute of a particular Python object as fast as possible from some C code. I wondered if using __slots__ to store the attribute would allow me to do this in a faster way. The reason I'd like to do this is because I need to access the attribut

Re: Regarding __slots__ and other stuff: A couple of questions

2008-03-27 Thread dave berk
hon_attributes_and_methods/python_attributes_and_methods.htm > > > <http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html>Descriptors > only works with type objects, not instance. and you can't write from an > instance object to a > class

Re: Regarding __slots__ and other stuff: A couple of questions

2008-03-27 Thread dave berk
s only works with type objects, not instance. and you can't write from an instance object to a class variable. You can only hide it. Also __slots__ works by creating descriptors in the class and preventing creation of any atrributes in the class instance, so everything is clear now Da

Re: Regarding __slots__ and other stuff: A couple of questions

2008-03-27 Thread Gabriel Genellina
En Thu, 27 Mar 2008 11:27:42 -0300, dave berk <[EMAIL PROTECTED]> escribió: > *first:* > Why doesn't this works? > >>>> class C(object): > ... __slots__ = ['foo', 'bar'] > ... class_attr = 'class attribute' > ... >&

Regarding __slots__ and other stuff: A couple of questions

2008-03-27 Thread dave berk
ml as well as here: http://users.rcn.com/python/download/Descriptor.htm There are still a couple of issues I'm unclear about. I'll be very happy if one of you could help me. *first:* Why doesn't this works? >>> class C(object): ... __slots__ = ['foo', 'bar&#

Re: It's ok to __slots__ for what they were intended

2007-12-22 Thread John Nagle
Fredrik Lundh wrote: > John Nagle wrote: > >> I'd like to hear more about what kind of performance gain can be >> obtained from "__slots__". I'm looking into ways of speeding up >> HTML parsing via BeautifulSoup. If a significant speedup can b

Re: It's ok to __slots__ for what they were intended

2007-12-21 Thread MrJean1
You are correct. Mea culpa. /Jean Brouwers On Dec 21, 1:41 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > MrJean1 wrote: > > My milage does vary, see this older post > > >   > > > Similar figures are shown with Python 2.5, bot

Re: It's ok to __slots__ for what they were intended

2007-12-21 Thread Chris Mellon
On Dec 21, 2007 2:07 PM, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > John Nagle wrote: > > > I'd like to hear more about what kind of performance gain can be > > obtained from "__slots__". I'm looking into ways of speeding up > > HTML parsin

Re: It's ok to __slots__ for what they were intended

2007-12-21 Thread Fredrik Lundh
MrJean1 wrote: > My milage does vary, see this older post > > > > Similar figures are shown with Python 2.5, both for 32- and 64-bit. unless I'm missing something, you're measuring object creation time. I'm measuring attribu

Re: It's ok to __slots__ for what they were intended

2007-12-21 Thread MrJean1
t; >      I'd like to hear more about what kind of performance gain can be > > obtained from "__slots__".  I'm looking into ways of speeding up > > HTML parsing via BeautifulSoup.  If a significant speedup can be > > obtained when navigating large trees of

Re: It's ok to __slots__ for what they were intended

2007-12-21 Thread Fredrik Lundh
John Nagle wrote: > I'd like to hear more about what kind of performance gain can be > obtained from "__slots__". I'm looking into ways of speeding up > HTML parsing via BeautifulSoup. If a significant speedup can be > obtained when navigating large tree

Re: It's ok to __slots__ for what they were intended

2007-12-21 Thread John Nagle
Chris Mellon wrote: > On 20 Dec 2007 19:50:31 -0800, Aahz <[EMAIL PROTECTED]> wrote: >> In article <[EMAIL PROTECTED]>, >> Carl Banks <[EMAIL PROTECTED]> wrote: >>>> Someday I'll have time to write up a proper page about why you shouldn't >

Re: It's ok to __slots__ for what they were intended (was: Don't use __slots__ (was Re: Why custom objects take so much memory?))

2007-12-21 Thread Chris Mellon
s Mellon <[EMAIL PROTECTED]> wrote: > >>> > >>>You can reduce the size of new-style classes (inherit from object) by > >>>quite a bit if you use __slots__ to eliminate the class dictionary. > >> > >> You can also reduce your functionality quit

Re: It's ok to __slots__ for what they were intended (was: Don't use __slots__ (was Re: Why custom objects take so much memory?))

2007-12-20 Thread Aahz
-style classes (inherit from object) by >>>quite a bit if you use __slots__ to eliminate the class dictionary. >> >> You can also reduce your functionality quite a bit by using __slots__. >> Someday I'll have time to write up a proper page about why you shouldn't

Re: It's ok to __slots__ for what they were intended (was: Don't use __slots__ (was Re: Why custom objects take so much memory?))

2007-12-18 Thread Carl Banks
On Dec 18, 4:49 pm, [EMAIL PROTECTED] (Aahz) wrote: > In article <[EMAIL PROTECTED]>, > > Chris Mellon <[EMAIL PROTECTED]> wrote: > > >You can reduce the size of new-style classes (inherit from object) by > >quite a bit if you use __slots__ to eliminate th

RE: Don't use __slots__ (was Re: Why custom objects take so much memory?)

2007-12-18 Thread Delaney, Timothy (Tim)
Aahz wrote: > In article <[EMAIL PROTECTED]>, > Chris Mellon <[EMAIL PROTECTED]> wrote: >> >> You can reduce the size of new-style classes (inherit from object) by >> quite a bit if you use __slots__ to eliminate the class dictionary. > > You can als

Don't use __slots__ (was Re: Why custom objects take so much memory?)

2007-12-18 Thread Aahz
In article <[EMAIL PROTECTED]>, Chris Mellon <[EMAIL PROTECTED]> wrote: > >You can reduce the size of new-style classes (inherit from object) by >quite a bit if you use __slots__ to eliminate the class dictionary. You can also reduce your functionality quite a bit by using __

Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-15 Thread Aahz
In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> wrote: >Aahz wrote: >> In article <[EMAIL PROTECTED]>, >> Steven Bethard <[EMAIL PROTECTED]> wrote: >>> >>> You can use __slots__ [...] >> >> Aaaugh! Don

Re: Don't use __slots__

2007-10-08 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes: > Well, I've read the thread, and I've read the thread it links to, > and for the life of me I'm still no clearer as to why __slots__ > shouldn't be used except that: [...] > But is there actually anything *ha

Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Steven Bethard
Aahz wrote: > In article <[EMAIL PROTECTED]>, > Steven Bethard <[EMAIL PROTECTED]> wrote: >> You can use __slots__ [...] > > Aaaugh! Don't use __slots__! > > Seriously, __slots__ are for wizards writing applications with huuuge > numbers of object i

Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Diez B. Roggisch
Steven D'Aprano wrote: > On Mon, 08 Oct 2007 15:15:36 +0200, Diez B. Roggisch wrote: > >>> Well, I've read the thread, and I've read the thread it links to, and >>> for the life of me I'm still no clearer as to why __slots__ shouldn't >&

Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Steven D'Aprano
On Mon, 08 Oct 2007 15:15:36 +0200, Diez B. Roggisch wrote: >> Well, I've read the thread, and I've read the thread it links to, and >> for the life of me I'm still no clearer as to why __slots__ shouldn't >> be used except that: >> >> 1 Aah

Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Diez B. Roggisch
Steven D'Aprano wrote: > On Sun, 07 Oct 2007 21:27:31 -0700, Aahz wrote: > >> In article <[EMAIL PROTECTED]>, Steven >> Bethard <[EMAIL PROTECTED]> wrote: >>> >>>You can use __slots__ [...] >> >> Aaaugh! Don't use __slo

Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Steven D'Aprano
On Sun, 07 Oct 2007 21:27:31 -0700, Aahz wrote: > In article <[EMAIL PROTECTED]>, Steven > Bethard <[EMAIL PROTECTED]> wrote: >> >>You can use __slots__ [...] > > Aaaugh! Don't use __slots__! > > Seriously, __slots__ are for wizards writi

Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-07 Thread Michele Simionato
On Oct 8, 12:27 am, [EMAIL PROTECTED] (Aahz) wrote: > > Aaaugh! Don't use __slots__! +1 QOTW ;) Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list

Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-07 Thread Aahz
In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> wrote: > >You can use __slots__ [...] Aaaugh! Don't use __slots__! Seriously, __slots__ are for wizards writing applications with huuuge numbers of object instances (like, millions of instances). For a

Re: pickle and __slots__

2007-10-04 Thread JL
I added the following method to the 2 subclasses of asyncore.dispatcher and asynchat.async_chat and now pickle works: def __getstate__(self): return Later I will probably modify this method so it returns something more interesting. Thanks for your help! I was confused because I am not

Re: pickle and __slots__

2007-10-04 Thread JL
> Is this a subclass? Look at the parent classes. Its class is a subclass of a similar class, but it indirectly references instances of subclasses of asyncore.dispatcher or asynchat.async_chat. I don't think there are other particular classes. If I remove the first references, pickle works. A

Re: pickle and __slots__

2007-10-04 Thread John Nagle
JL wrote: > Hello, > > I am trying to pickle an object, and I get: > > TypeError: a class that defines __slots__ without defining > __getstate__ cannot be pickled > > I didn't find __slots__ in the object or the class. Is there a way to > find it, or to to know

pickle and __slots__

2007-10-04 Thread JL
Hello, I am trying to pickle an object, and I get: TypeError: a class that defines __slots__ without defining __getstate__ cannot be pickled I didn't find __slots__ in the object or the class. Is there a way to find it, or to to know which object or class causes the problem? Thanks --

Re: method names in __slots__ ??

2006-12-25 Thread Rob Williscroft
e if you add >> a class attribute to the slots, one way or another its as if you >> hadn't put it in there in the first place. > > Clearly? Not so. It takes up memory. A list of 1 million Adder > instances takes up about 68 Mb (Python 2.5 on Windows XP). With the > meth

Re: method names in __slots__ ??

2006-12-25 Thread John Machin
s up memory. A list of 1 million Adder instances takes up about 68 Mb (Python 2.5 on Windows XP). With the method names removed from the __slots__, it takes only about 44 Mb. [For comparison: with no __slots__ at all, it takes about 180 Mb] > > This will give the sam

Re: method names in __slots__ ??

2006-12-25 Thread Rob Williscroft
t doesn't make any difference if you add a class attribute to the slots, one way or another its as if you hadn't put it in there in the first place. This will give the same error, which shows its about class attributes and not just methods: class Adder(object): __slots__ = [

method names in __slots__ ??

2006-12-24 Thread John Machin
I have stumbled across some class definitions which include all/most method names in a __slots__ "declaration". A cut-down and disguised example appears at the end of this posting. Never mind the __private_variables and the getter/setter approach, look at the list of methods in the __s

Re: Multiple inheritance and __slots__

2006-12-14 Thread Larry Bates
[EMAIL PROTECTED] wrote: > Simon Brunning wrote: >> On 14 Dec 2006 05:23:33 -0800, [EMAIL PROTECTED] >> <[EMAIL PROTECTED]> wrote: >>> Hi all, >>> >From the google search, it seems its not possible to do the following. >>> >

Re: Multiple inheritance and __slots__

2006-12-14 Thread greg
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 yo

Re: Multiple inheritance and __slots__

2006-12-14 Thread Michele Simionato
[EMAIL PROTECTED] 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 hav

Re: Multiple inheritance and __slots__

2006-12-14 Thread [EMAIL PROTECTED]
Simon Brunning wrote: > On 14 Dec 2006 05:23:33 -0800, [EMAIL PROTECTED] > <[EMAIL PROTECTED]> wrote: > > Hi all, > > >From the google search, it seems its not possible to do the following. > > > > >>> class Test1(object): > > ...

Re: Multiple inheritance and __slots__

2006-12-14 Thread Simon Brunning
On 14 Dec 2006 05:23:33 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi all, > >From the google search, it seems its not possible to do the following. > > >>> class Test1(object): > ... __slots__ = ['a'] > ... > >>> class Te

Multiple inheritance and __slots__

2006-12-14 Thread [EMAIL PROTECTED]
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__ = [

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-29 Thread Antoon Pardon
On 2006-08-27, Jacob Hallen <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > Patrick Maupin <[EMAIL PROTECTED]> wrote: > > Unfortunately there is a side effect to slots. They change the behaviour of > the objects that have slots in a way that can be abused by control freaks > and stat

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-28 Thread Patrick Maupin
Dieter Maurer wrote: > "Patrick Maupin" <[EMAIL PROTECTED]> writes on 26 Aug 2006 12:51:44 -0700: > > ... > > The only > > problem I personally know of is that the __slots__ aren't inherited, > > "__slots__" *ARE* inherited, although t

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-28 Thread Dieter Maurer
"Patrick Maupin" <[EMAIL PROTECTED]> writes on 26 Aug 2006 12:51:44 -0700: > ... > The only > problem I personally know of is that the __slots__ aren't inherited, "__slots__" *ARE* inherited, although the rules may be a bit complex. >>&

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-27 Thread David Isaac
"Jacob Hallen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Unfortunately there is a side effect to slots. They change the behaviour of > the objects that have slots in a way that can be abused by control freaks > and static typing weenies. This is bad, because the contol freaks s

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-27 Thread Patrick Maupin
Jacob Hallen wrote: > Patrick Maupin <[EMAIL PROTECTED]> wrote: > >Also, as I noted, I _do_ use them on occasion, so if there really _are_ > >potential pitfalls there, I would like to understand exactly what they > >are, so my ears perk up whenever I notice a __slots__

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-27 Thread Jacob Hallen
's probably >right. In my previous post, I attempted to rationalize why this is >true. For a start, Guido is probably continually hounded by people >asking stupid __slots__ questions. > >Nonetheless, this is one of the few topics on CLP where innocent, >rational questions are more

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-26 Thread Carl Banks
Patrick Maupin wrote: > The only assertion that was made explicitly enough to be testable came > about in a followup to Aahz's original post, only AFTER someone asked > what the side-effects associated with __slots__ were. Aahz responded: > > > The main one is that inheri

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-26 Thread Patrick Maupin
Jarek Zgoda wrote: > Having that said, should we hope __slots__ would disappear in (some) > future (tomorrow?!, in next 10 microseconds?!)? Please, don't left us > hopeless. > Are you saying you _do_ hope that __slots__ disappear? Why? Regards, Pat -- http://mail.python.org

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-26 Thread Patrick Maupin
[EMAIL PROTECTED] wrote: > Aahz> Taking a look at __slots__ is fine as long as you don't actually > Aahz> use them. > > Gabriel> Why? > > Skip> > http://groups.google.com/group/comp.lang.python/browse_thread/thread/451ad25f9c648404/f4ac2dfde32b16

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-26 Thread Jarek Zgoda
ython 3000 mailing list archives: > > http://mail.python.org/pipermail/python-3000/ > > though Ian Bicking asks about it here: > > > http://wiki.python.org/moin/Python3%2e0Suggestions#head-fc89a0fe3f697418776925f4828ea863031fbbd2 Having that said, should we hope __slo

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-26 Thread skip
Aahz> Taking a look at __slots__ is fine as long as you don't actually Aahz> use them. Gabriel> Why? Skip> http://groups.google.com/group/comp.lang.python/browse_thread/thread/451ad25f9c648404/f4ac2dfde32b16fd?lnk=st&q=Python+__slots__+aahz&rnum=2#f4ac

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-26 Thread Patrick Maupin
[EMAIL PROTECTED] wrote: > Aahz> Taking a look at __slots__ is fine as long as you don't actually > Aahz> use them. > > Gabriel> Why? > http://groups.google.com/group/comp.lang.python/browse_thread/thread/451ad25f9c648404/f4ac2dfde32b16fd?lnk=st&a

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs.object attributes)

2006-08-25 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I think that the official python documentation has to become more like > wikipedia, where people can fix it more easely, so I can add such > warning into the text. comment away: http://pyref.infogami.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-25 Thread bearophileHUGS
Aahz wrote: > Taking a look at __slots__ is fine as long as you don't actually use them. I remember the recent discussion about such matters... but I don't understand its dangers fully still. I assume __slots__ may be removed in Python 3.0, but maybe "experts" need it

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-25 Thread skip
Aahz> Taking a look at __slots__ is fine as long as you don't actually Aahz> use them. Gabriel> Why? http://groups.google.com/group/comp.lang.python/browse_thread/thread/451ad25f9c648404/f4ac2dfde32b16fd?lnk=st&q=Python+__slots__+aahz&rnum=2#f4ac2dfde

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-25 Thread Gabriel Genellina
At Friday 25/8/2006 11:34, Aahz wrote: >The results seem okay. Python is a dynamic language, object attributes >(and methods, etc) are kept inside a dict, where you can add and remove >them when you like. So using a dict is faster. >You can also take a look at __slots__ Taki

Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-25 Thread Aahz
okup can be precompiled. > >The results seem okay. Python is a dynamic language, object attributes >(and methods, etc) are kept inside a dict, where you can add and remove >them when you like. So using a dict is faster. >You can also take a look at __slots__ Taking a look at __

Re: Don't use __slots__! (was Re: dicts vs classes)

2006-07-28 Thread Aahz
In article <[EMAIL PROTECTED]>, Roy Smith <[EMAIL PROTECTED]> wrote: >>Guido sez: >> >> __slots__ is a terrible hack with nasty, hard-to-fathom side >> effects that should only be used by programmers at grandmaster and >> wizard level

Re: Don't use __slots__! (was Re: dicts vs classes)

2006-07-25 Thread Roy Smith
>Guido sez: > > __slots__ is a terrible hack with nasty, hard-to-fathom side > effects that should only be used by programmers at grandmaster and > wizard levels. Unfortunately it has gained an enormous undeserved > popularity amongst the novices and apprentice

Re: Don't use __slots__! (was Re: dicts vs classes)

2006-07-25 Thread Aahz
In article <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> wrote: >Aahz, citing Guido: >> >>__slots__ is a terrible hack with nasty, hard-to-fathom side >>effects that should only be used by programmers at grandmaster and >>wizard levels. Unfortunately it has gai

Re: Don't use __slots__! (was Re: dicts vs classes)

2006-07-25 Thread bearophileHUGS
Aahz, citing Guido: >__slots__ is a terrible hack with nasty, hard-to-fathom side >effects that should only be used by programmers at grandmaster and >wizard levels. Unfortunately it has gained an enormous undeserved I think I have used __slots__ just one time. Can you tell me some of of

Don't use __slots__! (was Re: dicts vs classes)

2006-07-25 Thread Aahz
m in a very short time. >> >> i was wondering if there is any benefit in using dicts instead from a >> performance/memory usage point of view? > >If you really have a memory problem read the documentation about >`__slots__`. But I would only consider this if `a lot of` is se

Re: __getattribute__ and __slots__

2006-04-17 Thread Peter Otten
have a __slots__ defined to be strict attributes, __slots__ is a performance/memory optimization. Using __slots__ to introduce bondage & discipline through the backdoor is against Python's spirit. > - return None if the attribute is 'ok' but not set, or raise a 'normal&#

__getattribute__ and __slots__

2006-04-14 Thread pascal . parent
Hi, I try to define a (new-style) class who: - have a __slots__ defined to be strict attributes, - return None if the attribute is 'ok' but not set, or raise a 'normal' error if the attribute isn't in __slots__. This code runs, but is it the good way? Thanks. class tes

Re: __slots__

2006-03-27 Thread Klaas
David wrote: > 3. What is a simple example of a Pythonic use of __slots__ that does NOT > involved the creation of **many** instances. mu. Your question presupposes the existence of such an example. -Mike -- http://mail.python.org/mailman/listinfo/python-list

Re: __slots__

2006-03-27 Thread Antoon Pardon
Op 2006-03-27, Georg Brandl schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> Op 2006-03-25, John J. Lee schreef <[EMAIL PROTECTED]>: >>> [EMAIL PROTECTED] (Alex Martelli) writes: >>> [...] you should be using pychecker or pylint >>> [...] >>> >>> I'm curious, as somebody who doesn't regu

Re: __slots__

2006-03-27 Thread Georg Brandl
Antoon Pardon wrote: > Op 2006-03-25, John J. Lee schreef <[EMAIL PROTECTED]>: >> [EMAIL PROTECTED] (Alex Martelli) writes: >> [...] >>> you should be using pychecker or pylint >> [...] >> >> I'm curious, as somebody who doesn't regularly use these tools: How do >> they fit into your workflow? Do

Re: __slots__

2006-03-27 Thread Antoon Pardon
Op 2006-03-25, John J. Lee schreef <[EMAIL PROTECTED]>: > [EMAIL PROTECTED] (Alex Martelli) writes: > [...] >> you should be using pychecker or pylint > [...] > > I'm curious, as somebody who doesn't regularly use these tools: How do > they fit into your workflow? Do you run them every few hours,

Re: __slots__

2006-03-25 Thread Ben Caradoc-Davies
John J. Lee wrote: > [EMAIL PROTECTED] (Alex Martelli) writes: >>you should be using pychecker or pylint > > I'm curious, as somebody who doesn't regularly use these tools: How do > they fit into your workflow? Do you run them every few hours, every > day, every time you run functional tests, eve

Re: __slots__

2006-03-25 Thread Alex Martelli
John J. Lee <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] (Alex Martelli) writes: > [...] > > you should be using pychecker or pylint > [...] > > I'm curious, as somebody who doesn't regularly use these tools: How do > they fit into your workflow? Do you run them every few hours, every > day, e

  1   2   >