# operations.py
def add(a,b):
return a+b
from operations import add
# "From file (or module) operations.py import object add"
result = add(1,2)
.py files)from calculator.operations import add
from calculator.representations import hexa
a = hexa(1)
b = hexa(2)
result = add(a,b)
Let’s rewrite both scripts scripts/analysis.py and scripts/show_extremes.py
as a collection of functions that can be reused in separate scripts.
The directory analysis1/tstools/ contains 3 python modules that contain (incomplete) functions performing
the same operations on data described in the original scripts analysis.py and show_extremes.py:
python-packaging-workshop/
scripts/
analysis1/
tstools/
__init__.py
moments.py
vis.py
extremes.py
moments.py and complete function get_mean_and_var (replace the
string "######").vis.py and complete functions plot_trajectory_subset and
plot_histogram (replace the strings "######").Use scripts/analysis.py as a reference.
You can run the test script tests.py in analysis1/ to test that everything is working fine.
The file tstools/extremes.py implements a function show_extremes corresponding to script show_extremes.py.
It is already complete.