On 2/23/07, James Stroud <[EMAIL PROTECTED]> wrote: > Troy Melhase wrote: > >> Why do people sometimes use one leading underscore? > > > > > > Many folks like to use the single leading underscore to emphasize that > > the attribute isn't part of the normal way to use the class or > > instance. > > > > It's bad style in my opinion, but I'm probably in the minority. > > I've increasingly found that leading underscores are unnecessary as well > if not using a "magic" attribute with the bounding double underscores. > --
I use the single underscore a lot and should use it more. It indicates something that you shouldn't look at unless you understand and are willing to bind yourself to the class internals. For example, I have a network interface that buffers data as it's being parsed. The internal buffer is a list named _buffer, and messing with the buffer is a good way to break the parser. There's an exterior interface, which is a guaranteed consistent buffer called "message", but (even for me, the author) it's easy to get confused about which one is the safe, public attribute and which one is private. The underscore disambiguates. -- http://mail.python.org/mailman/listinfo/python-list