modelx.export_members#

export_members(space: BaseSpace, module='__main__')[source]#

Export members of a space to a module’s global namespace.

This function defines global variables in the specified module for all static members (spaces, cells, refs) of the given space.

The global variables are named the same as the member names and reference the corresponding member objects. By default, the members are exported to the __main__ module, making them accessible directly in the main script or interactive shell.

Parameters:
  • space – The space whose members are to be exported.

  • module (str, optional) – The name of the module to which the members will be exported. Defaults to '__main__'.

Example

>>> import modelx as mx

>>> s = m.new_space()   # Create a new model and space

>>> @mx.defcells
... def foo(x):
...     return x

>>> del foo  # Remove foo from __main__

>>> foo(5)  # Raises NameError: name 'foo' is not defined

>>> mx.export_members(s) # Export members to __main__

>>> foo(5)  # Now foo is accessible in __main__
5