Two instances of Neuron in a Python script

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

Moderator: hines

Post Reply
Posts: 19
Joined: Mon Jul 02, 2007 6:18 am
Location: Humboldt-University, Berlin

Two instances of Neuron in a Python script

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


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

Thank you,
Posts: 15
Joined: Thu Mar 02, 2006 5:26 am
Location: Lausanne

Re: Two instances of Neuron in a Python script

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