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

Re: __slots__

2006-03-25 Thread John J. Lee
[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, every release, every

Re: __slots__

2006-03-25 Thread Duncan Booth
Ron Garret wrote: > [EMAIL PROTECTED] (Alex Martelli) wrote: > >> > One other question I did not get answered: is there any >> > simple example of a Pythonic use of __slots__ that does NOT >> > involve the creation of **many** instances. >> >> Since the only benefit of __slots__ is saving a fe

Re: __slots__

2006-03-25 Thread Alex Martelli
Ron Garret <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > [EMAIL PROTECTED] (Alex Martelli) wrote: > > > > One other question I did not get answered: is there any > > > simple example of a Pythonic use of __slots__ that does NOT > > > involve the creation of **many** instances.

Re: __slots__

2006-03-25 Thread Ron Garret
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Alex Martelli) wrote: > > One other question I did not get answered: is there any > > simple example of a Pythonic use of __slots__ that does NOT > > involve the creation of **many** instances. > > Since the only benefit of __slots__ is saving

Re: __slots__

2006-03-25 Thread Alex Martelli
David Isaac <[EMAIL PROTECTED]> wrote: ... > Does this beg the question of whether __slots__ > *should* break with inheritance? How would you expect the following code to behave: class Base(object): def __init__(self): self.x = 23 class Derived(Base): __slots__ = 'y', ? I would expe

Re: __slots__

2006-03-25 Thread David Isaac
"Aahz" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Because __slots__ breaks with inheritance. I believe that was the point of Ziga's example, which I acknowledged as a good one in my reply. So there still appears to be this single reason, which applies if your class may be subcla

Re: __slots__

2006-03-24 Thread Aahz
In article <[EMAIL PROTECTED]>, David Isaac <[EMAIL PROTECTED]> wrote: >"Ziga Seilnacht" <[EMAIL PROTECTED]> wrote: >> >> If you want to restrict attribute asignment, you should use the >> __setattr__ special method, see: >> http://docs.python.org/ref/attribute-access.html > >That "should" is what

Re: __slots__

2006-03-23 Thread David Isaac
"Ziga Seilnacht" <[EMAIL PROTECTED]> wrote: > If you want to restrict attribute asignment, you should use the > __setattr__ special method, see: > http://docs.python.org/ref/attribute-access.html That "should" is what I am asking about. If I understand, in the simplest case, you want me to say so

Re: __slots__

2006-03-23 Thread Ziga Seilnacht
David Isaac wrote: > 1. "Without a __dict__ variable, > instances cannot be assigned new variables not listed in the __slots__ > definition." > > So this seemed an interesting restriction to impose in some instances, > but I've noticed that this behavior is being called by some a side effect > the

Don't use __slots__ (was Re: __slots__ in derived class)

2006-03-15 Thread Aahz
In article <[EMAIL PROTECTED]>, =?ISO-8859-1?Q?Sch=FCle_Daniel?= <[EMAIL PROTECTED]> wrote: > >does __slots__ nothing when used in derived classes? Short answer: don't use __slots__ until you're comfortable writing metaclasses and decorators. __slots__ are a performance hack strictly for advance

Re: __slots__ in derived class

2006-03-15 Thread Duncan Booth
Schüle Daniel wrote: > consider this code > > >>> class A(object): > ... def __init__(self): > ... self.a = 1 > ... self.b = 2 > ... > >>> class B(A): > ... __slots__ = ["x","y"] > ... > >>> b=B() > >>> b.a > 1 > >>> b.b > 2 > >>> b.x = 100 > >>> b.y = 100 > >>> b.

Re: __slots__ in derived class

2006-03-15 Thread Kay Schluehr
Schüle Daniel wrote: > Hello, > > consider this code > > >>> class A(object): > ... def __init__(self): > ... self.a = 1 > ... self.b = 2 > ... > >>> class B(A): > ... __slots__ = ["x","y"] > ... > >>> b=B() > >>> b.a > 1 > >>> b.b > 2 > >>> b.x = 100 > >>> b

Re: __slots__ and copy again: why does it work?

2005-12-26 Thread fortepianissimo
To be complete, the first code snippet, when modified as follows, works fine in Python 2.4.2: --- START --- #!/usr/bin/env python import copy class Foo (object): __slots__ = ('i', ) def __init__ (self): self.i = 10 class Bar (Foo): __slots__ = ('j', ) def __init__ (self): supe

Re: __slots__ and copy again: why does it work?

2005-12-26 Thread limodou
26 Dec 2005 20:33:35 -0800, fortepianissimo <[EMAIL PROTECTED]>: > Mystery solved - when there's only one slot I should've used __slots__ > = ('i', ). Duh! > > So in short, __slots__ and copy.copy() work fine in Python 2.4.2. > Hard works, but very useful :) -- I like python! My Blog: http://www.

Re: __slots__ and copy again: why does it work?

2005-12-26 Thread fortepianissimo
Mystery solved - when there's only one slot I should've used __slots__ = ('i', ). Duh! So in short, __slots__ and copy.copy() work fine in Python 2.4.2. -- http://mail.python.org/mailman/listinfo/python-list

Re: __slots__ and copy again: why does it work?

2005-12-26 Thread fortepianissimo
More weird observations: the following code does not work until you change the name of the member 'longer' to a one-char name, for example, 'j': --- START --- #!/usr/bin/env python import copy class Foo (object): __slots__ = 'i' class Bar (Foo): __slots__ = 'longer' #__slots__ = 'j'

Re: __slots__ and copy again: why does it work?

2005-12-26 Thread fortepianissimo
I should've mentioned this was tested on Python 2.4.2. fortepianissimo wrote: > I remember from painful experience that copy.copy() won't really copy > __slots__ members. But I have trouble explaning why the following code > works: > > --- START--- > #!/usr/bin/env python > > import copy > > > cl

Re: __slots__ and class attributes

2005-11-04 Thread Ewald R. de Wit
Steven Bethard wrote: > But why do you want a class level attribute with the same name as an > instance level attribute? I would have written your class as: > > class A(object): > __slots__ = ['value'] > def __init__(self, value=1): > self.value = value > > where the default va

Re: __slots__ and class attributes

2005-11-03 Thread Steven Bethard
Ewald R. de Wit wrote: > I'm running into a something unexpected for a new-style class > that has both a class attribute and __slots__ defined. If the > name of the class attribute also exists in __slots__, Python > throws an AttributeError. Is this by design (if so, why)? > > class A( object ):