Re: Use of __slots__

2006-02-27 Thread Alex Martelli
MrJean1 <[EMAIL PROTECTED]> wrote: > An example of the RARE use case may be this particular one > > A benchmark is not a use case. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Use of __slots__

2006-02-27 Thread MrJean1
An example of the RARE use case may be this particular one /Jean Brouwers -- http://mail.python.org/mailman/listinfo/python-list

Re: Use of __slots__

2006-02-27 Thread Don Taylor
Alex Martelli wrote: > meant for extremely RARE use, and only by very advanced programmers who > fully know what they're doing Yea, from the table of my memory I ’ll wipe away all trivial fond records of __slots__ (Bet you wish Mark Lutz had not mentioned it in Learning Python ...) Don. --

Re: Use of __slots__

2006-02-27 Thread Alex Martelli
Don Taylor <[EMAIL PROTECTED]> wrote: ... > Does Python have the notion of static class attributes? No. > Just what was going on when I redefined my __slots__ attribute? Nothing. > It looks as if __slots__ is something really special, or I am managing Yep: it acts at *class-creation time*,

Re: Use of __slots__

2006-02-27 Thread Don Taylor
Steve Juranich wrote: > I might be a little confused about a couple of things (I'm sure many will > correct me if I'm not), but as I understand it the __slots__ attribute is a > class-attribute, which means it cannot be modified by an instance of the > class (think of a "static" class member, if y

RE: Use of __slots__

2006-02-26 Thread Delaney, Timothy (Tim)
Steve Juranich wrote: > IMHO, __slots__ is unpythonic. Many others have stated so on the > list. That's why it's great that you're free to ignore that variable. > I suggest that you do so (as I have chosen to do). I'm sure that > there are situations where you *MUST* have this kind of capability

Re: Use of __slots__

2006-02-26 Thread Steve Juranich
Don Taylor wrote: > I am puzzled about the following piece of code which attempts to create > a class that can be used as record or struct with a limited set of > allowed attributes that can be set into an instance of the class. > > I don't understand why I cannot set an attribute 'age' into reco

Re: Use of __slots__

2006-02-26 Thread Crutcher
Steven is right, however, there is a way: def new_record(slotlist): class R(object): __slots__ = slotlist return R() record1 = new_record(["age", "name", "job"]) record1.age = 27 record1.name = 'Fred' record1.job = 'Plumber' record1.salary = 5 -- http://mail.python.org/mailman/listi

Re: Use of __slots__

2006-02-26 Thread Steven D'Aprano
On Sun, 26 Feb 2006 17:01:45 -0500, Don Taylor wrote: > Hi: > > I am puzzled about the following piece of code which attempts to create > a class that can be used as record or struct with a limited set of > allowed attributes that can be set into an instance of the class. > > class RecordClass