London | 25-SDC-July | Eyuel Abraham | Sprint 4 | Implementing cowsay#157
London | 25-SDC-July | Eyuel Abraham | Sprint 4 | Implementing cowsay#157eyuell21 wants to merge 4 commits intoCodeYourFuture:mainfrom
Conversation
|
|
||
| # Dynamically call the animal function (like cowsay.turtle("hello")) | ||
| try: | ||
| animal_func = getattr(cowsay, args.animal) |
There was a problem hiding this comment.
You can check out an alternative get_output_string method here to avoid getattr (not the best choice to use if there is alternative - it make code more readable).
implement-cowsay/cow.py
Outdated
| try: | ||
| animal_func = getattr(cowsay, args.animal) | ||
| output = animal_func(message) | ||
| print(output) |
There was a problem hiding this comment.
You program always prints none in the end, please debug why this is and fix (should be a simple fix :) )
…ad of returning output
| animal_func = getattr(cowsay, args.animal) | ||
| output = animal_func(message) | ||
| print(output) | ||
| if output is not None: |
There was a problem hiding this comment.
So can you explain in which cases the output is None here and when it is not None?
There was a problem hiding this comment.
Output is None only if the animal function doesn't return anything. In the official cowsay module, it always returns a string.
The output is not None in normal cases because standard cowsay animal functions return a string of ASCII art.
There was a problem hiding this comment.
Why does it print None when you remove if output is not None:? What is considered to be not a normal case?
Learners, PR Template
Self checklist
Changelist
Python implementation of Cowsay.
Questions
Ask any questions you have for your reviewer.