I wanted a dictionary of hoc stuff for reasons that in retrospect was unnecessary, but having done this I thought I would share it
hdict = dict([(name,h.__getattribute__(name)) for name in dir(h) if hasattr(h,name)])
the hasattr() turned out to be the trick since for reasons obscure some things turn up in the dir() that are not accessible -- thanks to robert mcdougal for showing me that
note that this is not a dynamic dict so has to be regenerated after loading something
hdict['tstop'] # not found
h.load_file("stdrun.hoc")
hdict = dict([(name,h.__getattribute__(name)) for name in dir(h) if hasattr(h,name)])
hdict['tstop'] # 5.0
generate dictionary of hoc (h.) things
Moderator: hines
Re: generate dictionary of hoc (h.) things
in python 2.7+ can also do dict comprehensions so
hdict = {name:h.__getattribute__(name) for name in dir(h) if hasattr(h,name)}
hdict = {name:h.__getattribute__(name) for name in dir(h) if hasattr(h,name)}