modelx.cur_space#
- cur_space(space=None)[source]#
Get or set the current space of the current model.
When called without arguments, returns the current space. When called with a space argument, sets that space as current and returns it.
The current space is used as the default space for operations like
defcells()decorator and determines where new cells are created when no space is explicitly specified.Setting a space as current also sets its parent model as the current model.
- Parameters:
space (str or
UserSpace, optional) –The space to set as current. Can be:
- Returns:
The current space, or
Noneif no current space exists.- Return type:
UserSpaceor None
Example
>>> import modelx as mx >>> >>> m = mx.new_model('Model1') >>> s1 = m.new_space('Space1') >>> s2 = m.new_space('Space2') >>> >>> # Get current space >>> mx.cur_space() <UserSpace Model1.Space2> >>> >>> # Set current space by object >>> mx.cur_space(s1) <UserSpace Model1.Space1> >>> >>> # Set current space by name >>> mx.cur_space('Space2') <UserSpace Model1.Space2>
See also
new_space(): Create a new spacecur_model(): Get or set current model