Quesion about the proper use of __slots__
Zefria
zefria at gmail.com
Mon Feb 20 03:35:08 EST 2006
More information about the Python-list mailing list
Mon Feb 20 03:35:08 EST 2006
- Previous message (by thread): Quesion about the proper use of __slots__
- Next message (by thread): Quesion about the proper use of __slots__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>>> 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] ... self.weapon = statsTuple[3] ... self.bulk = statsTuple[4] ... __slots__ = [self.fuel,self.life,self.armor,self.weapon,self.bulk] ... >>> ral = Fighter() >>> ral.rocks = 2 >>> ral.rocks 2 >>> ral.life 5 I was reading the special methods, got to slots (http://docs.python.org/ref/slots.html) and decided that i should use this to save memory in the program because it'll have to support very large numbers of fighers at once. It says that once you define slots then you can't add any variables not listed in slots, but from that example section I just did, so am I doing something wrong or did I read it wrong?
- Previous message (by thread): Quesion about the proper use of __slots__
- Next message (by thread): Quesion about the proper use of __slots__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list