Single python file distribution: module or package?
Posted
by
DanielSank
on Programmers
See other posts from Programmers
or by DanielSank
Published on 2014-06-04T19:01:28Z
Indexed on
2014/06/04
21:41 UTC
Read the original article
Hit count: 420
Suppose I have a useful python function or class (or whatever) called useful_thing
which exists in a single file. There are essentialy two ways to organize the source tree. The first way uses a single module:
- setup.py
- README.rst
- ...etc...
- foo.py
where useful_thing
is defined in foo.py
. The second strategy is to make a package:
- setup.py
- README.rst
- ...etc...
- foo
|-module.py
|-__init__.py
where useful_thing
is defined in module.py
. In the package case __init__.py
would look like this
from foo.module import useful_thing
so that in both cases you can do from foo import useful_thing
.
Question: Which way is preferred, and why?
EDIT: Since user gnat says this question is poorly formed, I'll add that the official python packaging tutorial does not seem to comment on which of the methods described above is the preferred one. I am explicitly not giving my personal list of pros and cons because I'm interested in whether there is a community preferred method, not generating a discussion of pros/cons :)
© Programmers or respective owner