Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access attributes with dot operator with python fhicl module #6

Open
knoepfel opened this issue Oct 28, 2021 · 0 comments
Open

Access attributes with dot operator with python fhicl module #6

knoepfel opened this issue Oct 28, 2021 · 0 comments
Labels
feature An enhancement to the project

Comments

@knoepfel
Copy link
Contributor

This issue has been migrated from https://cdcvs.fnal.gov/redmine/issues/24091 (FNAL account required)
Originally created by @ikatza on 2020-02-26 10:22:45


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?

@knoepfel knoepfel added the feature An enhancement to the project label Oct 28, 2021
@knoepfel knoepfel added this to Issues Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature An enhancement to the project
Projects
Status: No status
Development

No branches or pull requests

1 participant