[Python-Dev] slots and default values (original) (raw)
Guido van Rossum guido@python.org
Tue, 13 May 2003 09:57:46 -0400
- Previous message: [Python-Dev] __slots__ and default values
- Next message: [Python-Dev] __slots__ and default values
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Was there a reason that slots makes initialized variables read-only? It would be useful to have overridable default values (even if it entailed copying them into an instance's slots):
class Pane(object): slots = ('background', 'foreground', 'size', 'content') background = 'black' foreground = 'white' size = (80, 25) p = Pane() p.background = 'light blue' # override the default assert p.foreground == 'white' # other defaults still in-place
You can't do that. The class variable 'background' overrides the descriptor created by slots. background now appears read-only because there is no instance dict.
--Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] __slots__ and default values
- Next message: [Python-Dev] __slots__ and default values
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]