section.allseg() means all nodes rather than all segments and produces the same result as for(x) in hoc?
True.
for seg in sec
iterates over the internal nodes of sec, i.e. nodes with range >0 and <1, just like hoc's
secname for (x,0)
for seg in sec.allseg()
iterates over all nodes of sec, including the nodes at 0 and 1, just like hoc's
secname for (x)
All that your example needs to prove the point beyond question is to print seg.x as well as seg.diam.
Iterating over all nodes, whether in hoc or Python, can produce identically misleading results, as is the case with your own example:
Code: Select all
testsection2:
300.0
320.0
340.0
360.0
380.0
After exiting the loop, 300 will not be the diam at 0, nor will 360 be the diam at 0.833 (i.e. at the last internal node. Check the diameters with
Code: Select all
for seg in sec.allseg():
print sec.x, sec.diam
and you will discover that the actual outcome is
Code: Select all
0.0 320.0
0.166... 320.0
0.5 340.0
0.833... 380.0
1.0 380.0
Exactly the same results are generated by the hoc equivalent
Code: Select all
dend for (x) {
diam(x) = 300+j
j += 20
print diam(x)
}
dend for (x) print diam(x)
The rule is that attempting to access a range variable at the 0 or 1 location actually accesses the range variable at the adjacent internal node.