I'm creating a script to automate plethora of related tasks, however I'd like to be able to run specific parts of the script from command line, such as C:\> python main.py --debug
(or just -d)
Or something like C:\> python main.py --log
(or just -l)
I've tried a lot of websites and videos but I haven't been able to find a solution. I've read the python docs but I don't really understand it very much yet as I'm very very beginner level. I don't want to have to run python main.py -l True
or -l Yes
or anything, I just want to be able to set a boolean to True if -l
is present.
I'm using arparse and I just want to be able to say, if the script is run with argument "-d", then set variable x to True Similarly, if script is run with argument "-l" then it would set y to True
I have been able to set up descriptions
import argparse
myparser = argparse.ArgumentParser(description='Script for logging and analyzing player data')
myparser.add_argument('--debug', '-d', required=False, action='debug_mode', help='Run in DEBUG Mode')
myparser.add_argument('--log', '-l', required=False, action='logger', help='Only run loggers')
myparser.add_argument('--autorun', '-a' required=False, action='enable_autorun', help='Logs data every day')
I don't want to require the arguments either, I want them to be optional.
I'm very new to python and I genuinely don't understand this argparse module, any help would be greatly appreciated :))