Page 1 of 1

Two instances of Neuron in a Python script

Posted: Wed Aug 20, 2008 12:28 pm
by arb
I tried to create a python class, that should create an instance of neuron:

Here a very simple example:

class neuron():

def __init__(self, tstop):
import neuron
self.h = neuron.h
self.h("tstop = %d"%tstop)

n1 = neuron(100)
n2 = neuron(500)

print n1.h.tstop
print n2.h.tstop

I expected that once a new object is created also a new neuron object will be created.. The neuron.h variable however seems to be kind of global: the result of this script ist:

500.0
500.0

Is it possible to create different hoc objects that do not see each other??

Thank you,
Armin

Re: Two instances of Neuron in a Python script

Posted: Fri Aug 22, 2008 1:45 pm
by emuller
Modules in python are singleton. Therefore, all references made in a running program are to the same module.

As a result, neuron.h is one and the same object each time you import it in the constructor.