-
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathcow.py
More file actions
27 lines (21 loc) · 727 Bytes
/
cow.py
File metadata and controls
27 lines (21 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import argparse
import cowsay
def main():
# Set up argument parser
parser = argparse.ArgumentParser(description="Make animals say things")
parser.add_argument("message", nargs="+", help="The message to say.")
parser.add_argument(
"--animal",
choices=cowsay.char_names,
default="cow",
help="The animal to be saying things.",
)
args = parser.parse_args()
# Combine the message into a single string
message = " ".join(args.message)
# Get the animal function dynamically
animal_function = getattr(cowsay, args.animal, cowsay.cow)
# Print the message using the selected animal
print(animal_function(message))
if __name__ == "__main__":
main()