Skip to content
Achilleas Koutsou edited this page Feb 9, 2018 · 1 revision

NixIO Object Naming Example

The following example illustrates how object naming and object overwriting is handled when reading and writing using the NixIO.

Create a new Block with a Neo name and write it.

>>> nixio = NixIO("/home/achilleas/tmp/nameexample.nix", "rw")
>>> neoblock = neo.Block("block one")
>>> nixio.write_block(neoblock)
>>> print(nixio.read_all_blocks())
[<neo.core.block.Block object at 0x7f4398ed6fd0>]

At this point, neoblock has been assigned a unique nix_name.

>>> print(neoblock.annotations)
{'nix_name': 'neo.block.b0737538cd054596b2b42b0e025be7b3'}

Now we change an attribute on neoblock and write it again.

neoblock.description = "the first block"
nixio.write_block(neoblock)

Since neoblock already had a nix_name, the existing Block in the file was overwritten.

>>> print(nixio.read_all_blocks())
[<neo.core.block.Block object at 0x7f4398e79f98>]

Creating a new Neo Block, even with the same (Neo) name and writing it to the file, adds a second Block to the file.

>>> neoblock = neo.Block("block one")
>>> nixio.write_block(neoblock)
>>> print(nixio.read_all_blocks())
[<neo.core.block.Block object at 0x7f4398e808d0>, <neo.core.block.Block object at 0x7f4398e6f208>]

Each Block in the file now has a unique nix_name, but they retain their Neo names on read.

>>> print([b.annotations["nix_name"] for b in nixio.read_all_blocks()])
['neo.block.b0737538cd054596b2b42b0e025be7b3', 'neo.block.fa4343cb12f543b097597cedf2daa2a8']
>>> print([b.name for b in nixio.read_all_blocks()])
['block one', 'block one']
Clone this wiki locally