1

I am writing a sizable side project in python and I have got a module which implements all database access with only functions declared within the module.I was wondering if there is anyway to declare functions in the module as public so that python knows that these are the only functions that should be used from outside the module.

1
  • You don't need: Python allows use of every part of everything from everywhere ;) Perhaps you meant to ask the reverse question, i.e. how to make stuff inaccesible from the outside? Not that it would be possible... Commented Dec 31, 2011 at 16:44

3 Answers 3

2

Don't preface them with _ (underscore).

According to PEP 8 -- Style Guide for Python Code:

public attributes should have no leading underscores

Sign up to request clarification or add additional context in comments.

Comments

1

No. The convention is to prefix private names with a single underscore, e.g. _foo.

Comments

1

Declare a module-level variable named __all__. This is a tuple of strings and will be the only symbols imported by from module import * and the only names that appear in help(module).

2 Comments

But that won't actually affect the public interface of the module.
This is the closest you get in Python: the developer telling you "here, use these."