Skip to content

Commit f54f334

Browse files
committed
argparse new parser
1 parent 338992e commit f54f334

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

intro/create_a_command_line_parse/using_argparse.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,17 @@
55
import argparse
66

77
if __name__ == '__main__':
8-
# Create interface
8+
# Create parser object with it's documentation
99
parser = argparse.ArgumentParser(description='Echo input')
10+
# adds position based command with it's help message
11+
parser.add_argument('message', help='Message to echo')
12+
13+
parser.add_argument('--twice', '-t', help='Do it twice',
14+
action='store_true')
15+
16+
args = parser.parse_args()
17+
18+
print(args.message)
19+
20+
if args.twice:
21+
print(args.message)

0 commit comments

Comments
 (0)