accessing hoc from python

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

Moderator: hines

Post Reply
stil
Posts: 28
Joined: Thu Jul 01, 2010 8:47 am
Location: Mulhouse - France

accessing hoc from python

Post by stil » Wed Apr 04, 2012 3:27 am

I have this 'bug' when using python : If ido

Code: Select all

from scipy import *
, and then

Code: Select all

h.load_file(whatever.hoc)
, the variables written in the hoc file like

Code: Select all

x = 0.001
will be seen as 0.
If i change for

Code: Select all

x = 1e-3
, or if i import

Code: Select all

import scipy as sc
, and adapt the code accordingly, the hoc variables are not ceiled.

regards

ted
Site Admin
Posts: 5572
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: accessing hoc from python

Post by ted » Wed Apr 04, 2012 3:36 pm

Have you read the Programmer's Reference material on Python_accessing_hoc ?
http://www.neuron.yale.edu/neuron/stati ... essing_Hoc

stil
Posts: 28
Joined: Thu Jul 01, 2010 8:47 am
Location: Mulhouse - France

Re: accessing hoc from python

Post by stil » Wed Apr 04, 2012 6:16 pm

thanks for the link ted, i just realize that there is a dedicated section in the programmers' reference.

I used documentations in http://www.davison.webfactional.com/not ... oc-python/, somehow kept using a regular hoc file for all the model description, and used python for all the surrounding tasks (simulation control, plotting)...

What i mentionned can be easily worked-around, but i was wondering the reason for this behavior. Do you suggest to write 'everything' in the same language, to make a choice between hoc and python ... ?

thanks again, anyway.

ted
Site Admin
Posts: 5572
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: accessing hoc from python

Post by ted » Wed Apr 04, 2012 9:24 pm

stil wrote:I used documentations in http://www.davison.webfactional.com/not ... oc-python/, somehow kept using a regular hoc file for all the model description, and used python for all the surrounding tasks (simulation control, plotting)...
That's fine. Just remember that a variable whose name in hoc is x will be called h.x in Python.
Do you suggest to write 'everything' in the same language, to make a choice between hoc and python
Not at all. Just pointing out that, if you want to use Python to refer to a variable that was created by a hoc statement, there is a way to do that. For example, if there is a hoc statement like
x = 0.001
then in Python
h.x
will have the value 0.001, but there may or may not be a Python variable called x, and even if there is one, it won't have anything to do with the hoc variable called x.

Post Reply