is possible to use isinstance() with Segment objects?

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
Nin
Posts: 41
Joined: Thu May 03, 2007 4:04 pm
Location: Institute of Science and Technology (IST Austria)
Contact:

is possible to use isinstance() with Segment objects?

Post 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
hines
Site Admin
Posts: 1687
Joined: Wed May 18, 2005 3:32 pm

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

Post 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
Post Reply