Mailing List Archive

Accessing configuration across multiple modules
Hi,

I am using Typer to create a command-line program with multiple levels
of subcommands, so a typical call might look like

mytool --config-file=~/test/mytool.conf serviceXYZ list people

In the top-level mytool.main, I evaluate the option '--config-file' and
read the config file to initialize the logging. This works fine.

However, in the module which lists people, namely

mytool.serviceXYZ.cli_people

I need to set up a connection to an LDAP server in order to actually
read the data.

If the LDAP connection details are also in the config file, what is the
best way of making them accessible at the point where the object
wrapping the LDAP server is initialized?

I found this a suggestion here which involves creating a separate module for
the configuration and then importing it

https://codereview.stackexchange.com/questions/269550/python-share-global-variables-across-modules-from-user-defined-config-file

I think I could probably get that to work, but are there any better
alternatives?

Cheers,

Loris

--
This signature is currently under constuction.
--
https://mail.python.org/mailman/listinfo/python-list