Skip to content

WIP : Singleton example

Sébastien DA ROCHA requested to merge singleton_example into 42_data_init

We could use a more simple syntax:

_ud_value = None

def get_ud_value():
    if _ud_value is None:
        _ud_value = get_last_ud_value()
    return _ud_value

Every function that needs ud value calls this function. The first call get the ud value and saves it, the next call just get the saved value.

The problem is Python forbids global variables to do this, so we have to pack it in a class. Hence the syntax that is a bit more complex.

Edited by Moul

Merge request reports