SOS - property question
Russell Blau
russblau at hotmail.com
Tue Sep 7 09:42:08 EDT 2004
"kepes.krisztian" <kepes.krisztian at peto.hu> wrote in message
news:mailman.2975.1094563441.5135.python-list at python.org...
>
> See that code:
> class A(object):
> __slots__=('x','a','__v')
> def __init__(self):
> self.__v=0
...
> Another question: why the __slots__ is working only if this member is in
> body of A ?
> Why isn't when it is in the __init__ procedure ?
>
> def __init__(self):
> self.__v=0
> __slots__=('x','a','__v')
>
I can't answer your first question, but I can the second. In the first
piece of code, you have defined __slots__ (correctly) as an attribute of the
class A. In the second piece, you have created a local variable called
__slots__ within the __init__() method. As soon as the __init__ method
returns, that local variable is gone!! Changing it to self.__slots__
wouldn't work either, because that would define an attribute of the
*instance*, not of the *class*. Slots and properties belong to the class,
not to its instances.
--
I don't actually read my hotmail account, but you can replace hotmail with
excite if you really want to reach me.
More information about the Python-list
mailing list