Project

General

Profile

Feature #24091

Access attributes with dot operator with python fhicl module

Added by Iker de Icaza Astiz 3 months ago. Updated 3 months ago.

Status:
Under Discussion
Priority:
Low
Assignee:
-
Target version:
-
Start date:
02/26/2020
Due date:
% Done:

0%

Estimated time:
Duration:

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 3 months ago

  • Status changed from New to Under Discussion
  • Tracker changed from Idea to Feature


Also available in: Atom PDF