Directly accessing segment of Section() object
Posted: Tue Jul 17, 2012 12:47 pm
Hi All,
I had a question regarding segment access in a Section() object in python. Considering the following (trivial) minimal example:
Now given this, a valid operation might be to create a list of segments in 'sec':
One could access these segs directly now:
However, I'm wondering if it would be possible to create the __getitem__ property for a Section() object so one could access segments directly:
In other words, a Section() object is iterable to access each individual section, but in some cases it might be very useful to access a particular segment directly. Any information or help here would be greatly appreciated!
I had a question regarding segment access in a Section() object in python. Considering the following (trivial) minimal example:
Code: Select all
from neuron import h
# create a section
sec = h.Section()
# change nseg
sec.nseg = 3
# iterate and run trivial operation on each segment of sec
for seg in sec:
print seg
Code: Select all
>>> lseg = [seg for seg in sec]
>>> print lseg
[<nrn.Segment object at 0x10b7b04e0>, <nrn.Segment object at 0x10b7b0530>, <nrn.Segment object at 0x10b7b05d0>]
Code: Select all
>>> print lseg[0]
<nrn.Segment object at 0x10b7b04e0>
Code: Select all
>>> sec[0]
<nrn.Segment object at 0x10b7b04e0>