__slots__ and class attributes

Ewald R. de Wit erdewit at d-e-l-e-t-e.zonnet.nl
Fri Nov 4 15:35:35 CET 2005


Steven Bethard wrote:
> But why do you want a class level attribute with the same name as an 
> instance level attribute?  I would have written your class as:
>
> class A(object):
>      __slots__ = ['value']
>      def __init__(self, value=1):
>          self.value = value
>
> where the default value you put in the class is simply expressed as a 
> default value to the __init__ parameter.

Thanks for your explanation. The reason why I was doing it was
to have class-level defaults, so that one can easily adjust how
new instances will be made. I'm doing it now with capitilized
class attribute names to avoid the name clash.

--
  --  Ewald



More information about the Python-list mailing list