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)
activestate.com/ASPN/Cookbook/Python/Recipe/286195>, use of __slots__ made a measurable difference in performance - and since my aim was to replace `super(cls, self)` with `self.super`, getting as close to the performance of `super(cls, self)` was important. Eventually of course, I achieved my be

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

Use of __slots__

2006-02-26 Thread Don Taylor
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(object): __slots__ = ["foo"] def __init__(self, args):

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Zefria
I am aware of this; but with too much Java still running through my brain I've never bothered with the idea yet because that's simply not the way I learned and I've never had a chance to need new attributes for singular instances. "__slots__ is not a method, so it falls outside that purpose as sta

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Alex Martelli
Peter Hansen <[EMAIL PROTECTED]> wrote: > Alex Martelli wrote: > > Zefria <[EMAIL PROTECTED]> wrote: > >... > >>this special case I'm expecting each "carrier" to have up to 150 > >>fighters, and 3 to 5 carriers for each of the two teams, which comes > >>out to be quite large. > > > > The prob

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Peter Hansen
Alex Martelli wrote: > Zefria <[EMAIL PROTECTED]> wrote: >... >>this special case I'm expecting each "carrier" to have up to 150 >>fighters, and 3 to 5 carriers for each of the two teams, which comes >>out to be quite large. > > The problem with the spread of email is that it reduces the numbe

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Peter Otten
Dennis Lee Bieber wrote: > On Mon, 20 Feb 2006 12:44:49 +0100, Peter Otten <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > >> >> I have 256K, by the way. >> > Ouch... I pray it is not running some variation of Windows... (My > TRS-80 Model III/4 [upgraded motherboard, sam

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote: > Peter Otten wrote: > > > He could be working on a machine with < 1M RAM or some other > > > constraints. > > > > I have 256K, by the way. > > > Impressive, curious to know what kind of environment it is as it has > been a long time I have seen such limited spec. My fir

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Alex Martelli
Zefria <[EMAIL PROTECTED]> wrote: ... > this special case I'm expecting each "carrier" to have up to 150 > fighters, and 3 to 5 carriers for each of the two teams, which comes > out to be quite large. The problem with the spread of email is that it reduces the number of envelopes laying around,

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Steve Holden
[EMAIL PROTECTED] wrote: > Peter Otten wrote: > >>>He could be working on a machine with < 1M RAM or some other >>>constraints. >> >>I have 256K, by the way. >> > > Impressive, curious to know what kind of environment it is as it has > been a long time I have seen such limited spec. My first x86(

Re: Quesion about the proper use of __slots__

2006-02-20 Thread bruno at modulix
Zefria wrote: > Well, my computer tends to run at about 497 to 501 out of 504 MB of RAM > used once I start up Gnome, XMMS, and a few Firefox tabs, and I'd > prefer not to see things slipping into Swap space if I can avoid it, > and the fighter data would be only part of a larger program. > > And

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Peter Otten
[EMAIL PROTECTED] wrote: > > Peter Otten wrote: >> > He could be working on a machine with < 1M RAM or some other >> > constraints. >> >> I have 256K, by the way. >> > Impressive, curious to know what kind of environment it is as it has > been a long time I have seen such limited spec. My first x

Re: Quesion about the proper use of __slots__

2006-02-20 Thread bonono
Peter Otten wrote: > > He could be working on a machine with < 1M RAM or some other > > constraints. > > I have 256K, by the way. > Impressive, curious to know what kind of environment it is as it has been a long time I have seen such limited spec. My first x86(IBM PC) had more than that. -- htt

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Steven D'Aprano
On Mon, 20 Feb 2006 01:14:20 -0800, Zefria wrote: class Fighter(object): > ... '''Small one man craft that can only harm other fighters on > their own.''' > ... __slots__ = ["fuel","life","armor","weapon","bulk"] > ... def __init__(self,statsTuple=(50,5,0,(2,4),1)): > ...

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Peter Otten
[EMAIL PROTECTED] wrote: > > Zefria wrote: >> Well, my computer tends to run at about 497 to 501 out of 504 MB of RAM >> used once I start up Gnome, XMMS, and a few Firefox tabs, and I'd >> prefer not to see things slipping into Swap space if I can avoid it, >> and the fighter data would be only

Re: Quesion about the proper use of __slots__

2006-02-20 Thread bonono
Zefria wrote: > Well, my computer tends to run at about 497 to 501 out of 504 MB of RAM > used once I start up Gnome, XMMS, and a few Firefox tabs, and I'd > prefer not to see things slipping into Swap space if I can avoid it, > and the fighter data would be only part of a larger program. > > And

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Zefria
Well, my computer tends to run at about 497 to 501 out of 504 MB of RAM used once I start up Gnome, XMMS, and a few Firefox tabs, and I'd prefer not to see things slipping into Swap space if I can avoid it, and the fighter data would be only part of a larger program. And as I said, learning how to

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Zefria wrote: > Also, I don't generally do any optimization at all yet (as a highschool > student projects get trashed often enough no to bother over), but in > this special case I'm expecting each "carrier" to have up to 150 > fighters, and 3 to 5 carriers for each of the

Re: Quesion about the proper use of __slots__

2006-02-20 Thread bonono
Peter Otten wrote: > Zefria wrote: > > > Also, I don't generally do any optimization at all yet (as a highschool > > student projects get trashed often enough no to bother over), but in > > this special case I'm expecting each "carrier" to have up to 150 > > fighters, and 3 to 5 carriers for each

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Peter Otten
Zefria wrote: > Also, I don't generally do any optimization at all yet (as a highschool > student projects get trashed often enough no to bother over), but in > this special case I'm expecting each "carrier" to have up to 150 > fighters, and 3 to 5 carriers for each of the two teams, which comes >

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Zefria
>>> class Fighter(object): ... '''Small one man craft that can only harm other fighters on their own.''' ... __slots__ = ["fuel","life","armor","weapon","bulk"] ... def __init__(self,statsTuple=(50,5,0,(2,4),1)): ... self.fuel = statsTuple[0] ... self.life = stat

Re: Quesion about the proper use of __slots__

2006-02-20 Thread bruno at modulix
Zefria wrote: class Fighter: Old-style classes are deprecated, use new-style class wherever possible: class Fighter(object): > ... '''Small one man craft that can only harm other fighters on > their own.''' > ... def __init__(self,statsTuple=(50,5,0,(2,4),1)): > ...

Re: Quesion about the proper use of __slots__

2006-02-20 Thread bonono
Zefria wrote: > >>> class Fighter: > ... '''Small one man craft that can only harm other fighters on > their own.''' > ... def __init__(self,statsTuple=(50,5,0,(2,4),1)): > ... self.fuel = statsTuple[0] > ... self.life = statsTuple[1] > ... self.armor =

Quesion about the proper use of __slots__

2006-02-20 Thread Zefria
>>> class Fighter: ... '''Small one man craft that can only harm other fighters on their own.''' ... def __init__(self,statsTuple=(50,5,0,(2,4),1)): ... self.fuel = statsTuple[0] ... self.life = statsTuple[1] ... self.armor = statsTuple[2] ...