Steven W. Orr a écrit :
> I understand that two leading underscores in a class attribute make the 
> attribute private. 

Nope. It doesn't make it "private", it mangles the attribute name with 
the class name (ie : Bar.__mangled will become Bar._Bar__mangled 
everywhere except inside Bar). This is only useful when you want to make 
sure an attribute will not be *accidentally* accessed by a child class. 
FWIW, I've found it of very limited use so far...

> But I often see things that are coded up with one 
> underscore. Unless I'm missing something, there's a idiom going on here.

Yes. Single leading underscore means "this is implementation, don't mess 
with it or your on your own". It's the equivalent of "private".

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to