namespace for released packages?

Robert Brewer fumanchu at amor.org
Mon Jul 19 00:28:44 EDT 2004


Stuart Bishop wrote:
> It is pretty rare to get clashes - module authors are generally
> nice enough to make sure nobody else is using their package name
> before releasing things and generally package everything into
> a single top-level module.

Alex Hunsley replied: 
> Doesn't a single top level module translate into all the 
> source being in 
> one file? (please correct if I'm wrong about this!)

Let's be clear about terms: Python has 'modules' and 'packages'. Each
module is one file (on all platforms I can think of), whereas a package
consists of multiple module files*, all contained within a single
directory tree on a filesystem (the tree root == the name of the
package). So the phrase "package everything into a single top-level
module" is a bit misleading. Generally, you will find two kinds of
Pythonistas: those who write modules and those who write packages, and
they'll phrase their answers to such questions differently.

Despite these differences, modules and packages compete for the same
namespace at the top level.

So yes, a single top-level module literally means all the source being
in one file; for many Python projects, that works. For many others, that
doesn't work; hence packages. Use what works for your project. :)


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org

* OK, if you want to pick nits, you *could* make a package with just one
file, mypkg/__init__.py. But let's not cloud the issue. ;)



More information about the Python-list mailing list