Skip to content

Commit 338992e

Browse files
committed
argparse command line parser
1 parent f5dc15e commit 338992e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

intro/create_a_command_line_parse/parse.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env python3
22

3+
# * Getting arguments from the terminal in a vanilla way(no modules).
4+
5+
36
# We need the sys module
47
import sys
58

@@ -9,6 +12,9 @@ def user_greeting(greeting, name):
912
print(message)
1013

1114

15+
# The expression (if __name__ == '__main__':) will test if we are running the script from the terminal.
16+
17+
1218
if __name__ == '__main__':
1319
greeting = 'Hello'
1420
name = 'User'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env/ python3
2+
3+
# * Using Argparse module to handle command line arguments
4+
5+
import argparse
6+
7+
if __name__ == '__main__':
8+
# Create interface
9+
parser = argparse.ArgumentParser(description='Echo input')

0 commit comments

Comments
 (0)