These are chat archives for dbwebb-se/python

9th
Jan 2018
Longho
@blongho
Jan 09 22:54

too late but i have to ask. I am having problem with argparse
Relevant code:

#main.py
import sys
sys.path.append("../analyzer")

import analyzer
import cli_parser


def main():
    """
    Main function where it all starts.
    """
    option = cli_parser.parse_options()
    command = option["known_args"]["commands"]
    silent = option["known_args"]["silent"]
    verbose = option["known_args"]["verbose"]
    number = option["known_args"]["amount=<integer>"]
    fil = option["known_args"]["filename"]

    print(option["known_args"]) # to see which commands have been recieved
    if command == "all":
        if silent:
            print("Silent printing") # for debugging
            analyzer.show_silent("all", "../analyzer/" + fil)
        elif verbose:
            print("verbose printing")
            analyzer.show_verbose("all", "../analyzer/" + fil)
        else:
            print("default printing")
            analyzer.show_default("all", "../analyzer/" + fil)
    # lines
    elif command == "lines":
### 

# bash cmd
argparse(master) $ python3 main.py
usage: main.py [-h] [-v | -s] [-V | -a, --author] [--amount=<integer>]
               {all,lines,words,letters,word_frequency,letter_frequency} ...
               filename
main.py: error: the following arguments are required: filename
argparse(master) $ python3 main.py all phil.txt
{'commands': 'all', 'filename': 'phil.txt', 'verbose': 'False', 'silent': 'False', 'amount=<integer>': 'False'}
Silent printing
Letters: 907
Words: 199
Lines: 19
argparse(master) $ python3 main.py --silent all phil.txt
{'commands': 'all', 'filename': 'phil.txt', 'verbose': 'False', 'silent': True, 'amount=<integer>': 'False'}
Silent printing
Letters: 907
Words: 199
Lines: 19
argparse(master) $ python3 main.py --verbose all phil.txt
{'commands': 'all', 'filename': 'phil.txt', 'verbose': True, 'silent': 'False', 'amount=<integer>': 'False'}
Silent printing
Letters: 907
Words: 199
Lines: 19

Program seem to remain at silent
https://codeshare.io/5Nmx41