How to make a module function visible only inside the module?

beginner zyzhu2000 at
Sun Aug 19 03:46:57 CEST 2007

On Aug 18, 8:27 pm, ra... at (Lawrence Oluyede) wrote:
> beginner <zyzhu2... at> wrote:
> > Is there any equivalent version of C's static function in Python. I
> > know I can make a class function private by starting a function name
> > with two underscores, but it does not work with module functions.
> The trick for the name mangling does not work at module level. Anyway,
> if you read the PEP 8 [1] you can correctly write your code following a
> well known coding standard. A function like this:
> def _f():
>     pass
> is meant to be private, you can also state it in the function's
> docstring to be more clear, if you want, but it's not necessary
> > For exmaple, __func1 is still visible outside the module.
> Yes, and _f() will also be. There's no such thing as enforcing
> encapsulation in Python, even the "__method()" trick can be easily
> bypassed if you have to.
> 1 - <>
> --
> Lawrence, -
> "It is difficult to get a man to understand
> something when his salary depends on not
> understanding it" - Upton Sinclair

Thanks a lot. I was using two underscores, __module_method() as my
static method convention, and then I had some problems calling them
from inside class methods.

More information about the Python-list mailing list