Page 1 of 1

is possible to use isinstance() with Segment objects?

Posted: Sun Dec 12, 2010 10:57 am
by Nin
Hi everybody,

for debugging processes, I would like to test if an object passed as argument to a class is indeed a Segment. I though that checking it with isinstance() would be appropriate, but unfortunately this launches an error:

here a minimal example:

Code: Select all

from neuron import h

soma = h.Section(name = 'soma')
soma.nseg = 3
# a list of segments
soma_seg = [seg for seg in soma]
Before doing:

Code: Select all

stim = IClamp(soma_seg[1])
I would like to test if soma_seg[1] is a Segment...

but

Code: Select all

isinstance(soma_seg[1], h.Segment)
gives me

AttributeError: 'hoc.HocObject' object has no attribute 'Segment'

Am I doing something wrong?

Thanks a lot in advance

Re: is possible to use isinstance() with Segment objects?

Posted: Sun Dec 12, 2010 12:06 pm
by hines
Segment and Section are actually part of an internal nrn module so to use is_instance on those
you need
import nrn
then

>>> isinstance(soma_seg[1], nrn.Segment)
True