__init__, __slot__ and **keywordargs
zunbeltz at wm.lc.ehu.es.XXX
Fri Jan 9 13:25:59 CET 2004
Peter Otten <__peter__ at web.de> writes:
> You misspelt: in fact it's __slots__, and it will work as expected. As far
Hurg!!! :-( This kine of mistakes will become me crazy.
> as I know slots are an optimization technique that is useful to save some
> space, when you have many (that would be millions) of small objects. It's
> not meant as a safety belt for the programmer.
But, I think it can be considered "a safety belt for the programmer" ,
When you do
you get and AttributeError if attribute is not in the __slots__
(It would help to avoid misspells, like i've done!!)
> In your case, I wouldn't use it, but rather not initialize the attributes
> not given as constructor - __init__() - arguments. Also, I would consider
> the ability to provide additional arguments, say "Nickname", not a
> bug but
What do you mean with additional arguments? (My code was not the full
> a feature. Of course you have to change your client code to test for
Not yet :-) I'm in planning stage yet and this code was only to play a
bit to see what can i do.
> hasattr(person, "Birthday")
> instead of
> person.Birthday is None
Thanks for this suggestion, I think i'll use hasattr.
Remove XXX from email: zunbeltz at wm.lc.ehu.esXXX
More information about the Python-list