utility functions within a class?

blair.bethwaite at gmail.com blair.bethwaite at gmail.com
Mon May 8 06:23:48 CEST 2006


John Salerno wrote:
> What I originally meant was that they would not be called from an
> instance *outside* the class itself, i.e. they won't be used when
> writing another script, they are only used by the class itself.

Yep, so you want to encapsulate the functionality that those methods
provide, which is the whole point of building them in a class in the
first place.  And you want them to be private to the class so that they
do not form part of the classes public/external interface.

In python, as discussed earlier :), you can make them semi-private by
using the '__method_name' syntax.  The thing is that python doesn't
strictly enforce this privacy, code outside of your object can still
call these methods because python just mangles the internal method name
slightly.  See
http://docs.python.org/tut/node11.html#SECTION0011600000000000000000
for more detail.

Cheers,
-B




More information about the Python-list mailing list