Skip to content

Reference

Python template with some awesome tools to quickstart any Python project.

python_module_template

Module Docstring.

logger module-attribute

logger = getLogger('python_module_template')

Calculator

Class for simple calculator operations.

Source code in python_package_template/python_module_template.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Calculator:
    """Class for simple calculator operations."""

    @staticmethod
    def divide(a: float, b: float) -> float:
        """Divide a by b.

        Args:
            a (float): Dividend.
            b (float): Divisor.

        Returns:
            float: The result of the division.

        Raises:
            ZeroDivisionError: if b is 0.
            TypeError: if a or b are not float numbers.

        Examples:
            You can run this function as following.

            >>> Calculator.divide(2,1)
            2.0

        """
        if b == 0:
            raise ZeroDivisionError
        elif type(a) not in (float, int) or type(b) not in (float, int):
            raise TypeError
        return a / b

divide staticmethod

divide(a, b)

Divide a by b.

Parameters:

  • a (float) –

    Dividend.

  • b (float) –

    Divisor.

Returns:

  • float ( float ) –

    The result of the division.

Raises:

  • ZeroDivisionError

    if b is 0.

  • TypeError

    if a or b are not float numbers.

Examples:

You can run this function as following.

>>> Calculator.divide(2,1)
2.0
Source code in python_package_template/python_module_template.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@staticmethod
def divide(a: float, b: float) -> float:
    """Divide a by b.

    Args:
        a (float): Dividend.
        b (float): Divisor.

    Returns:
        float: The result of the division.

    Raises:
        ZeroDivisionError: if b is 0.
        TypeError: if a or b are not float numbers.

    Examples:
        You can run this function as following.

        >>> Calculator.divide(2,1)
        2.0

    """
    if b == 0:
        raise ZeroDivisionError
    elif type(a) not in (float, int) or type(b) not in (float, int):
        raise TypeError
    return a / b