-
-
Notifications
You must be signed in to change notification settings - Fork 42
Sheffield | 25-SDC-Nov | Hassan Osman | Sprint 4 | Implement cowsay in Python #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 21 commits
d64a62d
9ed0feb
5056da5
3e46eb0
9dbaa8f
98cea7c
e09ede3
56afb4f
778321f
e8e7d09
55d9cc9
cdc3bdd
7d49667
827e134
6490896
fa626b4
4bfcbb4
35ecdac
f39e5b5
49a4340
60cfbdf
2d9d0c4
01c6b73
128b09d
e58e3e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .venv/ | ||
| .env | ||
| .env.* | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import cowsay | ||
| import sys | ||
| import argparse | ||
|
|
||
| listed_animals = [listed_animal for listed_animal in dir(cowsay) if callable(getattr(cowsay, listed_animal)) and not listed_animal.startswith("__") and listed_animal not in ["draw", "func", "get_output_string", "CowsayError"]] | ||
|
|
||
| parser = argparse.ArgumentParser( | ||
| prog="cow", | ||
| description="Makes animals say things", | ||
| ) | ||
|
|
||
| parser.add_argument("--animal", help="Select an animal to say anything", choices=listed_animals) | ||
| parser.add_argument("message", nargs ="+", help="The message that the animal says") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| message = " ".join(args.message) | ||
| animal = args.animal or "cow" | ||
|
||
|
|
||
|
|
||
| if animal not in listed_animals: | ||
| print(f"Error: argument --animal: invalid choice: '{animal}'. Choose from: {', '.join(listed_animals)}") | ||
| exit(1) | ||
|
|
||
| animal_says = getattr(cowsay, animal) | ||
|
|
||
| print(animal_says(message)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| cowsay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might work, but looking over every single item in dir(cowsay) and manually excluding the ones you dont want might not be very maintainable in the long term. Is there an easier way to access this information?