Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

networkx.utils.decorators.nodes_or_number

nodes_or_number(which_args)[source]

Decorator to allow number of nodes or container of nodes.

Parameters

which_args (int or sequence of ints) – Location of the node arguments in args. Even if the argument is a named positional argument (with a default value), you must specify its index as a positional argument. If more than one node argument is allowed, can be a list of locations.

Returns

_nodes_or_numbers – Function which replaces int args with ranges.

Return type

function

Examples

Decorate functions like this:

@nodes_or_number(0)
def empty_graph(nodes):
    pass

@nodes_or_number([0,1])
def grid_2d_graph(m1, m2, periodic=False):
    pass

@nodes_or_number(1)
def full_rary_tree(r, n)
    # r is a number. n can be a number of a list of nodes
    pass