Skip to content

Commit 1085017

Browse files
committed
Add illustration for code organization
1 parent 0a11d70 commit 1085017

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

source-code/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ was used to develop it.
2525
1. `testing`: illustrates writing unit tests with `unittest` and
2626
`pytest`.
2727
1. `oo_vs_functional.ipynb`: comparing object-oriented approach to
28-
functional approach, including coroutines.
28+
functional approach, including coroutines.
2929
1. `metaclasses`: illustration of the use of metaclasses in Python.
3030
1. `data-structures`: illustration of Python and standard library data
3131
structures.
32+
1. `code-organization`: illustration of how to organize code in packages
33+
and modules.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Code organization
2+
3+
Simple example of code organization in packages, modules.
4+
5+
## What is it?
6+
7+
1. `my_pkg`: Python package.
8+
1. `__init__.py`: package-level documentation and version
9+
information.
10+
1. `my_module.py`: simple module in the `my_pkg` package.
11+
1. `my_script.py`: Python script that uses the `my_module`
12+
module in the `my_pkg` package.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'''
2+
This is the my_pkg documentation
3+
'''
4+
5+
__version__ = '1.0'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def hello(name):
2+
return f'hello {name}'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
3+
import my_pkg.my_module
4+
5+
print(my_pkg.my_module.hello('world'))

0 commit comments

Comments
 (0)