Feature #24091
Access attributes with dot operator with python fhicl module
Status:
Under Discussion
Priority:
Low
Assignee:
-
Target version:
-
Start date:
02/26/2020
Due date:
% Done:
0%
Estimated time:
Description
python/fhiclmodule.cc
defines a python module to be able to open a fcll file and put the contents on a python dict.
Accessing parameters can become cumbersome:
pset['parameter_table']['parameter_value']
A less cumbersome and more familiar way would be to do:
pset.parameter_table.parameter_value
In Python this is easily achieved by defining __getattr__()
function.
What I've done is:
On my python script define:
class dotDict(dict): def __getattr__(self,val): return self[val]
then feed this class with the python dict:
fcl_params = fhicl.make_pset('file_with_parameters.fcl') pset = dotDict(fcl_params) par = pset.parameter_table.parameter_value
Unfortunately I don't understand how to construct this code on the C++ implementation of this module.
Would this be something you would like to add to the module?
History
#1 Updated by Kyle Knoepfel 11 months ago
- Status changed from New to Under Discussion
- Tracker changed from Idea to Feature