configargparse - reading option from config only

Loris Bennett loris.bennett at fu-berlin.de
Fri Aug 27 03:37:42 EDT 2021


Richard Damon <Richard at Damon-Family.org> writes:

> On 8/26/21 6:01 AM, Loris Bennett wrote:
>> Hi,
>>
>> When using configargparse, it seems that if a value is to be read from a
>> config file, it also has to be defined as a command-line argument in
>> order to turn up as an attribute in the parser namespace.  
>>
>> I can sort of see why this is the case, but there are also some options
>> I would like to read just from the config file and not have them
>> available as command-line options.  This would be, say, to prevent the
>> number of options on the command-line from becoming bloated by
>> little-used settings.
>>
>> Is there an elegant way to do this?
>>
>> Cheers,
>>
>> Loris
>>
> Look at the read() member function to supply the file name to read. Then
> in the config object there will be sections for each section in the
> config file. No need for any of these to be 'options'

Do you have a link for this?  As far as I can see, the config files are
given in the following manner:

  p = configargparse.ArgParser(default_config_files=['/etc/app/conf.d/*.conf', '~/.my_settings'])

I can obviously just read the config file with configparser, but the
idea of configargparse is that an option can be specified as an option,
in a config file, or as an environment variable,

As far as I can tell, configargparse only loads entries from the config
file into the appropriate namespace if they have also been defined as
long options (i.e. with '--').  I was hoping to access *all* the config
file entries, regardless of whether they are also options, since the
config is obviously being read.

Cheers,

Loris

-- 
This signature is currently under construction.


More information about the Python-list mailing list