Use self.vars in class.method(parameters, self.vars)

Thomas Jollans t at
Fri Jul 22 14:58:08 EDT 2011

>> 2/ the argument name ('len') will shadow the builtin 'len' function
>> within this function's scope.
>>>                 self.__myvar = len
> I have experience in java programming so using function calling
> without () is foolish for me XD, but that a great suggestion

No function is being called. It's just that if you tried using the len()
function within that method (where there is a variable called `len'), it
wouldn't work: Python would take your variable and try to call it, not
the builtin function object.

> I do not really already understand the mechanism of using private
> public vars in python.

Everything is public.

self._foo (leading underscore) is, by convention, used for internal
member variables and methods.

Two leading underscores are the closest thing there is to "private": The
name is mangled, and won't be visible to subclasses or external code
under that name (but there's nothing preventing anybody from changing it)

More information about the Python-list mailing list