Basic inheritance question

Lie Lie.1296 at gmail.com
Mon Jan 14 13:15:08 EST 2008


On Jan 7, 2:46 am, Bruno Desthuilliers
<bdesth.quelquech... at free.quelquepart.fr> wrote:
> Lie a écrit :
>
> > On Jan 5, 5:40 pm, MartinRineh... at gmail.com wrote:
>
> >>Jeroen Ruigrok van der Werven wrote:
>
> >>>Shouldn't this be:
>
> >>>self.startLoc = start
> >>>self.stopLoc = stop
>
> >>Thanks! Of course it should. Old Java habits die slowly.
>
> > No, seriously it isn't Java habits only, most other languages wouldn't
> > need explicit calling of class name.
>
> Where is the "explicit calling of class name" exactly ?

Perhaps I was a bit tired when writing that (I wouldn't understand
what I wrote if I were you)... what I meant is most other languages
doesn't usually enforce us to explicitly state the containing class
name, which in python is generally called "self". Most other languages
1) automatically assign the containing class' object in a keyword
(Java: this, VB: Me) behind the screen, and 2) automatically searches
variable name in both the local variable table and the containing
class variable table (so to refer to a class variable named var from a
method inside the class, we only need to write var, not self.var as in
python). In VB, Me is extremely rarely used, in Python, self is all
over the place. Well, there is positive and negative to both sides,
convenience in VB, and flexibility in Python.

Compare the following codes:
VB.NET:
Public Class A
    Dim var
    Public Function aFunction()
        return var

Python:
class A:
    def aFunction(self):
        return self.var



More information about the Python-list mailing list