-3

Snippet of code:

import argparse

parser = argparse.ArgumentParser(description='Process some values.')

parser.add_argument('--proj', metavar='P', type=str, nargs= 1,
                    help='Identify the project')

parser.add_argument('--summ', metavar='S', type=str, nargs= '+',
                    help='Write a summary')

args = parser.parse_args()

a = vars(args)

print(a)

Execute python3 filename.py

Output:

{'proj': None, 'summ': None}

This is only a single line printed.

Instead I want to see:

{'proj' : None,

 'summ' : None}

This has multiple lines printed, thus easier to read output. Please clarify if any other detail needed.

WSLUser
  • 601
  • 5
  • 10
  • 2
    That's nothing to do with argparse, that's just how Python represents a dictionary. See https://stackoverflow.com/q/10279712/3001761 – jonrsharpe Nov 14 '18 at 20:39
  • Yes I removed the label but that still doesn't help me determine how to get the output to print multiple lines instead of a single line. – WSLUser Nov 14 '18 at 20:45
  • Easier readability. Eventually I'll be adding in user input for each of these arguments along with a few other things. – WSLUser Nov 14 '18 at 20:50
  • ballpointBen, thanks, I am eventually passing into a json file but not sure the width solutions will work. I just tried that pprint method and got TypeError: 'module' object is not callable – WSLUser Nov 14 '18 at 20:55

1 Answers1

1

You could try pretty-printing it:

>>> args = {'prog': None, 'summ': None}
>>> from pprint import pprint
>>> pprint(args)
{'prog': None,
'summ': None}

See this question/answer.

miike3459
  • 1,431
  • 2
  • 16
  • 32