Python Package tutorial

Contents

Python Package tutorial#

Run when documentation is build. Building documentation therefore can become an minimal integration test for the package.

from python_package import hello_world

Hello World#

mockup module contains a function which returns a string repeating the ‘hello world’ string n-times.

ret = hello_world(2)
ret
'hello world hello world'

Print the string.

print(ret)
hello world hello world

Inspect the signature. In an interactive session you could also use hello_world? to display the docstring. See the rendered version of hello_world under the Reference

help(hello_world)
Help on function hello_world in module python_package.mockup:

hello_world(n: int) -> str
    Print 'hello world' n-times.

    Parameters
    ----------
    n : int
        How many time to return hello world

    Returns
    -------
    str
        str of 'hello world' n-times

    Examples
    --------
    >>> hello_world(3)
    'hello world hello world hello world'

Simple example for a recipe showing what the package can do.