Skip to content

Commit 8e8de1a

Browse files
committed
implement cowsay
1 parent 4350f48 commit 8e8de1a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

implement-cowsay/cow.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import cowsay
2+
import argparse
3+
4+
# get valid animals dynamically from the library
5+
animals = [
6+
name for name in dir(cowsay)
7+
if name.islower() and callable(getattr(cowsay, name))
8+
]
9+
10+
parser = argparse.ArgumentParser(description="Make animals say things")
11+
12+
parser.add_argument(
13+
"message",
14+
nargs="+",
15+
help="The message to say."
16+
)
17+
18+
parser.add_argument(
19+
"--animal",
20+
choices=animals,
21+
default="cow",
22+
help="The animal to be saying things."
23+
)
24+
25+
args = parser.parse_args()
26+
27+
message = " ".join(args.message)
28+
29+
getattr(cowsay, args.animal)(message)

0 commit comments

Comments
 (0)