Packaging question

snorble snorble at hotmail.com
Thu Jul 1 17:15:36 EDT 2010


My question is, why do the modules bar and foo show up in mypack's
dir()? I intend for Foo (the class foo.Foo) and Bar (the class
bar.Bar) to be there, but was not sure about the modules foo and bar.

My big picture intention is to create smaller modules, but more of
them (like I am used to doing with C++), and then use a package to
organize the namespace so I'm not typing out excessively long names
and making the code less readable. Is that a reasonable approach to
developing Python programs?

$ ls mypack/*.py
bar.py
foo.py
__init__.py

$ cat mypack/__init__.py
from foo import Foo
from bar import Bar

$ python
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import mypack
>>> dir(mypack)
['Bar', 'Foo', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '__path__', 'bar', 'foo']
>>>



More information about the Python-list mailing list