Python 3K or Python 2.9?

TheFlyingDutchman zzbbaadd at aol.com
Wed Sep 12 19:43:53 CEST 2007


>
> "this" in C++ and Java is not shown in the parameter list, which was
> what he was
> complaining about.  He wants
>
> class MyClass:
>         def SomeFunction(someParameter):
>            self.someParameter = someParameter
>
> not
>
> class MyClass:
>         def SomeFunction(self, someParameter):
>            self.someParameter = someParameter
>
> The confusing way about the current Python method when you first
> encounter it is
>  why is "self" being passed in when you write the function but not
> when you call it. If the compiler is smart enough to know that
>
>     a = MyClass()
>     a.SomeFunction(12)
>
> SomeFunction() has a "self" implicitly added to the parameter list, it
> seems that it should be smart enough to know that a function defined
> in a class has a "self" implicitly added to the parameter list.

In C++ and Java I don't believe "this" is ever referred to as an
implicit function parameter. It is a (sometimes necessary) way to
reference the object inside one if it's methods. If it is in fact a
real parameter in the underlying compiled-code implementation, that
knowledge hurts more than it helps.




More information about the Python-list mailing list