Created
August 17, 2022 14:40
-
-
Save beardedfoo/ace1bfb5c0ff16fd299b36ea67ee4440 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""A hello world in python using argparse""" | |
import argparse | |
import sys | |
def parse_args(): | |
p = argparse.ArgumentParser(description=__doc__) | |
p.add_argument('name', help='The name of the entity to be greeted') | |
p.add_argument('--emoji', action='store_true', default=False, | |
help='Enables a hand wave emoji in the greeting') | |
p.add_argument('--language', | |
choices=['english', 'nederlands'], | |
default='english', | |
help='Sets the language for the greeting' | |
) | |
return p.parse_args() | |
def main(): | |
args = parse_args() | |
if args.language == 'english': | |
greeting = 'Hello' | |
elif args.language == 'nederlands': | |
greeting = 'Hoi' | |
if args.emoji: | |
print(f'{greeting} {args.name} 👋') | |
else: | |
print(f'{greeting} {args.name}') | |
if __name__ == '__main__': | |
sys.exit(main()) |
Author
beardedfoo
commented
Aug 17, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment