Question about idiomatic use of _ and private stuff.

goodwolf Robert.Katic at gmail.com
Fri Feb 23 19:09:59 EST 2007


On Feb 23, 5:12 pm, "Steven W. Orr" <ste... at syslang.net> wrote:
> I understand that two leading underscores in a class attribute make the
> attribute private. But I often see things that are coded up with one
> underscore. Unless I'm missing something, there's a idiom going on here.
>
> Why do people sometimes use one leading underscore?
>
> TIA
>
> --
> Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
> happened but none stranger than this. Does your driver's license say Organ ..0
> Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
> individuals! What if this weren't a hypothetical question?
> steveo at syslang.net

One underscore stay for 'protected'. Protected in OOP means that the
attribute is hidden outside the class but visible for subclasses. In
python one undersore is only a good convention for say that the
attribute is protected.
So users will ignore attributes with initial undersocre. Users who
subclass must know of that attributes existence for prevent unwonted
overriding.

Sory for my english.




More information about the Python-list mailing list