Page 1 of 1
Finding available variables in each section
Posted: Tue Dec 27, 2011 4:30 pm
by uri.cohen
I'm loading an existing hoc file into python and would like to list the available state variables in each compartment. For example, the soma has a variable 'v' in each location (available through h.soma(0.5).v). Is there a programmatic way to do so?
Thanks!
Re: Finding available variables in each section
Posted: Thu Dec 29, 2011 10:43 pm
by figoyouwei
Hi Hines :
I have the same question ! Although it has been asked by another post by mattioni, which the indirect way is "loop and check" whether a variable exists, but ...
Is there any direct way, like <$ dir(soma)> function which automatically lists all the range variables accessible from a Section or a Segment ?
ideally, it shall be
when you call <$ dir(soma)>, it lists : .v .ek .ena
when you call <$ dir(soma(0.5))>, it lists : .v .gk .gna
Thanks !
Re: Finding available variables in each section
Posted: Fri Dec 30, 2011 3:54 pm
by hines
you can try:
for sec in h.allsec():
for seg in sec:
for mech in seg:
for n in dir(mech):
if n.endswith(mech.name()):
print sec, seg, mech, n
Re: Finding available variables in each section
Posted: Fri Dec 30, 2011 3:55 pm
by hines
looks like I need to show it in code since all the indentation was removed above
Code: Select all
for sec in h.allsec():
for seg in sec:
for mech in seg:
for n in dir(mech):
if n.endswith(mech.name()):
print sec, seg, mech, n
Re: Finding available variables in each section
Posted: Fri Jan 13, 2012 11:42 am
by figoyouwei
Thanks Hines ! The 'n' print is what I want :-)