Defining private module functions in python

According to http://www.faqs.org/docs/diveintopython/fileinfo_private.html:

Like most languages, Python has the
concept of private elements:

  • Private
    functions, which can’t be called from
    outside their module

However, if I define two files:

#a.py
__num=1

and:

#b.py
import a
print a.__num

when i run b.py it prints out 1 without giving any exception. Is diveintopython wrong, or did I misunderstand something? And is there some way to do define a module’s function as private?

10 Answers
10

Leave a Comment