Why self?

Roy Smith roy at panix.com
Mon Jul 8 15:02:41 EDT 2002


Lou Pecora  <pecora at anvil.nrl.navy.mil> wrote:
>Solution? Sometimes I just use the underscore "_" as the self object
>reference.  That shortens the name.  You don't have to use the word
>"self."  viz.,
>
># Within the object definition, x and z are object variables ...
>
>     def func(_):
>         y=_.x * _.z
>         return y
>
>Not the best solution, but saves typing.

Saves typing, yes, but makes your code harder to understand by
somebody else who has to read and maintain it later.





More information about the Python-list mailing list