[Python] self implicito

Nicola Larosa nico a tekNico.net
Mer 3 Ott 2012 10:52:33 CEST


Walter Valenti wrote:
> Ho un metodo di una classe, che utilizza molti metodi di una classe
> padre, con la conseguenza che sono pieno di "self.qualcosa".
> C'è un modo per rendere implicito il "self"?

No, non c'è, per scelta progettuale.

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
...

Inoltre:

Why must ‘self’ be used explicitly in method definitions and calls?
<http://docs.python.org/faq/design.html#why-must-self-be-used-explicitly-in-method-definitions-and-calls>

Infine:

Why explicit self has to stay
<http://neopythonic.blogspot.it/2008/10/why-explicit-self-has-to-stay.html>

Hai due possibilità:

1) Impara ad apprezzare il "self" ovunque.
2) Cambia linguaggio.

Ciò che chiedi non è una soluzione, ma un modo per creare ulteriori problemi.

-- 
Nicola Larosa - http://www.tekNico.net/

The most formative influence on my politics was reading "The Rise
and Fall of the Third Reich" and thinking very hard about how Germany
went from the Weimar Republic to stoking the furnaces at Dachau. My
conclusion was that there is a short, straight path from statism to
genocide, and the only way to avoid that grimmest of destinations
is never to get on the train. - Eric Raymond, April 2012


Maggiori informazioni sulla lista Python