Nameable class¶
(Shortest import: from brian2 import Nameable)
-
class
brian2.core.names.
Nameable
(name)[source]¶ Bases:
brian2.core.tracking.Trackable
Base class to find a unique name for an object
If you specify a name explicitly, and it has already been taken, a
ValueError
is raised. You can also specify a name with a wildcard asterisk in the end, i.e. in the form'name*'
. It will then tryname
first but if this is already specified, it will tryname_1
,name__2`
, etc. This is the default mechanism used by most core objects in Brian, e.g.NeuronGroup
uses a default name of'neurongroup*'
.Parameters: name : str
An name for the object, possibly ending in
*
to specify that variants of this name should be tried if the name (without the asterisk) is already taken. If (and only if) the name for this object has already been set, it is also possible to call the initialiser withNone
for thename
argument. This situation can arise when a class derives from multiple classes that derive themselves fromNameable
(e.g.Group
andCodeRunner
) and their initialisers are called explicitely.Raises
ValueError
- If the name is already taken.
Attributes
id
A unique id for this object. name
The unique name for this object. Methods
assign_id
()Assign a new id to this object. Details
-
id
¶ A unique id for this object.
In contrast to names, which may be reused, the id stays unique. This is used in the dependency checking to not have to deal with the chore of comparing weak references, weak proxies and strong references.
-
name
¶ The unique name for this object.
Used when generating code. Should be an acceptable variable name, i.e. starting with a letter character and followed by alphanumeric characters and
_
.
-
assign_id
()[source]¶ Assign a new id to this object. Under most circumstances, this method should only be called once at the creation of the object to generate a unique id. In the case of the
MagicNetwork
, however, the id should change when a new, independent set of objects is simulated.