public and private members of the module

L

Lev Elblert

Acording to documentation the are 2 ways to "hide" functions, data
inside the module:

1. __all__ list
2. starting "hiden" names with underscore.

None of these methods does not work:

############################################
#File: foo.py
import sys
__all__ = ['B']
def A():
print "In A"
def B():
print "In B"
def _C():
print "In _C"
############################################
#File: a.py
import foo
print dir(foo)
foo.A()
foo.B()
foo._C()

Running a.py produces this output:

['A', 'B', '_C', '__all__', '__builtins__', '__doc__', '__file__',
'__name__', 'sys']
In A
In B
In _C

Can somebody explain this?

I'm working on Windows Python 2.3


Thanks in advance
 
D

Dennis Lee Bieber

Acording to documentation the are 2 ways to "hide" functions, data
inside the module:

1. __all__ list
2. starting "hiden" names with underscore.

None of these methods does not work:
Forgive me, but your double negative phrase is equal to "all of
these methods do work" <G>

And, they probably do... What you missed is that the "hide" only
applies to the use of

from module import *

The * will only pick up those in the __all__ list, or in on
__all__ then those not beginning with _

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,055
Members
47,659
Latest member
salragu

Latest Threads

Top