modelx.defcells

defcells(space=None, name=None, *funcs)[source]

Decorator/function to create/update cells from Python functions.

Convenience decorator/function to create a new cells or change the formula of an existing cells directly from a function definition or a function object, which substitutes for calling new_cells() or, set_formula() of the parent space or setting its formula property.

defcells() understands arguments passed to it in 3 different ways depending the number of the arguments and their types.

1. As a decorator without arguments

To create a cells from a function definition in the current space with the same name as the function’s:

@defcells
def foo(x):
    return x

Changed in version 0.1.0: If the current space does not exist in the current model, a new space is created. If the current model does not exit, a new model is also created.

Changed in version 0.1.0: If a cells with the same name already exists in the current space, the formula of the cells is updated based on the decorated function.

2. As a decorator with arguments

To create a cells from a function definition in a given space and/or with a given name:

@defcells(space=space, name=name)
def foo(x):
    return x

3. As a function

To create a multiple cells from a multiple function definitions:

def foo(x):
    return x

def bar(y):
    return foo(y)

foo, bar = defcells(foo, bar)
Parameters
  • space (optional) – For the 2nd usage, a space to create the cells in. Defaults to the current space of the current model.

  • name (optional) – For the 2nd usage, a name of the created cells. Defaults to the function name.

  • *funcs – For the 3rd usage, function objects. (space and name also take function objects for the 3rd usage.)

Returns

For the 1st and 2nd usage, the newly created single cells is returned. For the 3rd usage, a list of newly created cells are returned.