Why self?
Robb Shecter
rs at onsitetech.com
Mon Jul 8 15:24:41 EDT 2002
Lou Pecora wrote:
> In article <3D29DD1A.6040209 at onsitetech.com>, Robb Shecter
> <rs at onsitetech.com> wrote:
>
>
>>>> self.__velocity = self.__factor1 * self.__factor2
>>>
>
> You don't need the double underscores.
I feel like I need them because:
1. AFAIK, without them, subclasses can inadvertently cause problems.
2. I'm used to the OO/encapsulation idea of private scope being the
default.
3. It seems Pythonic: These variables aren't part of the public API,
and so the underscores give clues to some Python tools.
4. It seems Pythonic: The 'property' feature would be confusing if both
the new property, plus the internal representation were seen as being
public API.
Robb
More information about the Python-list
mailing list