I was trying to use a dynamically read in template_name with a spellcheck for "begintemplate" in the corresponding hoc morphology file to create python cell variables.
While this name extraction works and I retrieve the correct template_name, I tried to create a python cell with it, which was more difficult than expected.
So I have
Code: Select all
template_name = "templatename" -> string
Code: Select all
mycell = h.template_name
Code: Select all
h("objref cell"); h("cell = new templatename")
Well, gladly I found a solution, but I don't know why it works. The final one which was working was:
Code: Select all
mycell = getattr(h, template_name)(hoc_path)
Now I would really want to know, and therefore I ask here, if you know why it works with the path in the second braces behind the getattr(). Why does just giving the hoc path to the h.template_name method instantiate the cell, and why is it not doing it without the hoc_path? I know that it is basically the same like calling h.templatename(hoc_path), but why does it need that?
Best ~