Skip to content

Commit 9439121

Browse files
committed
use dest to identify which subparser used
1 parent f29f10d commit 9439121

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

module_argparse/argparse_subparsers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
parser = argparse.ArgumentParser()
55

6-
subparsers = parser.add_subparsers(help='commands')
6+
subparsers = parser.add_subparsers(help='commands', dest='command')
77

88
list_parser = subparsers.add_parser('list', help='list contents')
99
list_parser.add_argument('dirname', action='store', help='directory to list')
@@ -16,7 +16,10 @@
1616
delete_parser.add_argument('dirname', action='store', help='the directory to remove')
1717
delete_parser.add_argument('--recursive', '-r', default=False, action='store_true',
1818
help='remove the contents of the directory, too')
19-
print(parser.parse_args())
19+
20+
ns = parser.parse_args()
21+
print(ns)
22+
print()
2023

2124
# python argparse_subparsers.py -h
2225
# python argparse_subparsers.py list -h

playground/asyncio_abouts/more_on_asyncio_4/test_async_3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from pytest_mock import mocker
2+
33
from playground.asyncio_abouts.more_on_asyncio_4 import sample_24
44

55

0 commit comments

Comments
 (0)