![]() ![]() To add all the content from value to arg_dict, you shouldn't use àppend but extend. The name execute probably needs to be improved for something more meaningful. G = parser.add_argument_group('Device Targets') Removing the class, you get something like : def execute(): PyYAML module is not installed with Python by default. ![]() Pre-requisites: Install the PyYAML module PyYAML is the best module of Python to read the YAML file. The use of the PyYAML module to read the YAML file in Python has shown in this tutorial. ![]() If you do write a class, I find it clearer to have an init to define the different members but in your case, you could stop writing classes. Multiple modules exist in Python to read the YAML file. In your current version of the code, it is hard to see what is stored in an instance and how the data flows around the different methods. Then you can keep an isolated version that you maintain your self. I get this for the output: Namespace(age=, delay=30, name=, stupid=False) I suggest you fork an open licensed module like the Phil-Factor/PSYaml as this isn't a trivial task. If my config-file has the following data: name: Īnd I run my code like this: python test.py -conf args.txt -name 'Mark' G.add_argument('-stupid', dest='stupid', default=False, action='store_true') Even though PyYAML is the name of the library you’ve installed, you’ll be importing the yaml package in Python code. G.add_argument('-age', default=, action='append') To confirm if your PyYAML installation comes with a C binding, open the interactive Python interpreter and run this code snippet: >. G.add_argument('-name', default=, action='append') I am trying to parse the command line arguments using argparse, and if the user specifies a yaml file for the config-file, add those arguments to the args from argparse import argparse ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |