Private methods

Demian Brecht demianbrecht at gmail.com
Tue Oct 9 10:08:20 EDT 2012


On 12-10-09 06:59 AM, D.M. Procida wrote:
> In Python, using an underscore is simply a convention to note that a
> method is private - it doesn't actually hide it from other things -
> correct?
>
> Daniele
>

A single underscore semantically means private. A double underscore will 
name mangle the function such that it's only accessible strictly by name 
through the class that it's define in. Note that you *can* still access 
it if you understand how name mangling works. Nothing in Python is truly 
private.

-- 
Demian Brecht
@demianbrecht
http://demianbrecht.github.com



More information about the Python-list mailing list