Skip to content

Source Code

Adding Your Code

All source code (i.e. your various modules, functions, classes, and so on) should be placed in the /src/<MyPackageName> directory. A sample file named examples/sample.py is included here as a representative example, which you should replace.

All the code in the src directory can be imported now that you have installed your package.

Tip

As an example, you can import and use the demonstration template.examples.sample functions as follows:

from MyPackageName.examples.sample import add, make_array

print(add(1, 2))  # 3
print(make_array(3, length=4))  # [3, 3, 3, 3]

Note

For any subfolder within src/<MyPackageName> containing Python code, you must have an __init__.py file, which will tell Python that this is a module you can import.

Docstrings

The code comments beneath each function are called docstrings. They should provide an overview of the purpose of the function, the various parameters, and the return values (if any). Here, we are using the NumPy style docstrings, but you can pick a different style if you like later on.