Skip to main content

Load and gen configuration for argparse

Project description

Save/Load your options to/into config

>>> from arconfig import GenConfigAction, LoadConfigAction
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument("--config", action=LoadConfigAction) # add it before another options
>>> parser.add_argument("--gen-config", action=GenConfigAction)
>>> parser.add_argument('-s', action='store', dest='simple_value', help='Store a simple value')
>>> parser.add_argument('-c', action='store_const', dest='constant_value',
... const='value-to-store', help='Store a constant value')
>>> parser.add_argument('-t', action='store_true', default=False,
... dest='boolean_switch', help='Set a switch to true')
>>> parser.add_argument('-f', action='store_false', default=False,
... dest='boolean_switch', help='Set a switch to false')

Generate simple config:

$ python script.py --gen-config
{
 "simple_value": null,
 "constant_value": null,
 "config": null,
 "boolean_switch": false
}

And load it:

$ python argparse_config.py --gen-config > /tmp/test.json
$ python argparse_config.py --config=/tmp/test.json
{
 "simple_value": null,
 "constant_value": null,
 "config": null,
 "gen_config": false,
 "boolean_switch": false
}

All another arguments overwrite the config values (but counter are added).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arconfig-0.0.7.tar.gz (2.7 kB view details)

Uploaded Source

File details

Details for the file arconfig-0.0.7.tar.gz.

File metadata

  • Download URL: arconfig-0.0.7.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for arconfig-0.0.7.tar.gz
Algorithm Hash digest
SHA256 2c91f772810a8a346184facb8fd718fd8d83b3cb36ec6e43a0dbfc9844d820b3
MD5 1e489808966a689b0955c02b2e1952c9
BLAKE2b-256 eb140c681bf9aa932e8069c40f9f624b4f14ea5635b7dcdf062f2f28e96984cd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page