Reference

A Reference is a name binding. It binds a name, such as foo to an object. References are manually created by the user as attributes of UserSpace:

>>> space.foo = 1

When a Reference is created as an attribute of a UserSpace, the name becomes available in the namespace associated with the UserSpace. The Formulas of child Cells of the UserSpace are evaluated in the namespace, so the name that appears in the Formulas refers to the object that the name is bound to by the Reference. Continuing with the above example, suppose a Cells baz is defiened in the same Space space as foo:

>>> space.baz.formula
def baz():
    return foo

The foo in the baz definition referes to 1:

>>> space.baz()
1

References can also be created as attributes of Model objects. Such References become accessible from any Space in the Model. Suppose model is a Model object and the parent of space:

>>> model.bar = "bar"

bar defined above is also defined in space:

>>> space.bar
'bar'

And bar can be referred to from the Formulas of child Cells of model:

>>> def baz():
...     return bar

>>> space.baz = baz

>>> space.baz.formula
def baz():
    return bar

>>> space.baz()
'bar'

Reference objects themselves are hidden from the user, and the bound objects are always referenced by the names. To access the attributes of Reference objects, ReferenceProxy objects are used.

ReferenceProxy

class ReferenceProxy(impl)[source]

Proxy to interface to References

Reference objects are not exposed to the user, thus ReferenceProxy objects are used to interface to References. A proxy object to a Reference can be created and returned by the get_object() function, by passing the full dotted name of the Reference to name, and True to as_proxy:

>>> mx.get_object("Model1.Space1.foo", as_proxy=True)

Reference shares its ultimate base class with Model, Space and Cells classes, and below are attributes common among those classes.

name

The name of the Reference.

Type

str

fullname

The dotted name of the object.

Type

str

parent

The parent of the Reference.

model

The Model that the Reference belongs to.

Attributes

value

Returns referenced object

refmode

Returns reference mode