On Jan 30, 12:15 am, Chris Rebert <c...@rebertia.com> wrote: > - Python supports encapsulation. Prefixing an attribute/method with an > underscore indicates that other programmers should treat it as > 'private'. However, unlike B&D languages, Python itself does nothing > to enforce this privacy, leaving it instead to the good judgement of > the programmer, under the philosophy that "We're all consenting adults > here".
How do you know? (I know I'm not.) Seriously, though, the lack of private members does allow for ugly hacks in user code, and you know there are always ugly hackers. > This allows people to meddle with internals, at their own risk, > if it ends up being absolutely necessary. If it ends up being necessary, the class's design is flawed. (Though in this case, the flaw is easily solved by simply providing a getter.) > The enforcement point is > largely academic anyway, as most languages' reflection APIs let you > poke at ostensibly "private" things. If you're talking about getters, then note that this doesn't let you modify the member (unless there's a corresponding setter). In the absence of private/protected, Python should at least provide something similar to C++'s 'const' or Java's 'final'. (Similar, not equivalent, because then the object itself wouldn't be able to manipulate its own members!) -- http://mail.python.org/mailman/listinfo/python-list