Skip to content

Commit 418494a

Browse files
committed
Add an example module
1 parent 57e7d5c commit 418494a

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

source/tutorials/packaging-projects.rst

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,22 @@ Create the following file structure locally:
3535
packaging_tutorial/
3636
└── src/
3737
└── example_package/
38-
└── __init__.py
38+
├── __init__.py
39+
└── example.py
3940
40-
:file:`src/example_package/__init__.py` is required to import the directory as a
41-
package, and should be empty. If you are unfamiliar with Python's modules and
41+
:file:`__init__.py` is required to import the directory as a package, and
42+
should be empty.
43+
44+
:file:`example.py` is an an example of a module within the package that could
45+
contain the logic (functions, classes, constants, etc.) of your package.
46+
Open that file and enter the following content:
47+
48+
.. code-block:: python
49+
50+
def add_one(number):
51+
return number + 1
52+
53+
If you are unfamiliar with Python's :term:`modules <Module>` and
4254
:term:`import packages <Import Package>`, take a few minutes to read over the
4355
`Python documentation for packages and modules`_.
4456

@@ -64,7 +76,8 @@ When you're done, the project structure will look like this:
6476
├── setup.cfg
6577
├── src/
6678
│   └── example_package/
67-
│   └── __init__.py
79+
│   ├── __init__.py
80+
│   └── example.py
6881
└── tests/
6982
7083
@@ -564,7 +577,9 @@ and import the package:
564577

565578
.. code-block:: python
566579
567-
>>> import example_package
580+
>>> from example_package import example
581+
>>> example.add_one(2)
582+
3
568583
569584
Note that the :term:`import package <Import Package>` is ``example_package``
570585
regardless of what ``name`` you gave your :term:`distribution package <Distribution

0 commit comments

Comments
 (0)