-
-
Notifications
You must be signed in to change notification settings - Fork 42
London | 25-SDC-July | Eyuel Abraham | Sprint 4 | Implementing cowsay #157
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 1 commit
5af07ad
e448fe5
96c0d12
687e4d8
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 |
|---|---|---|
|
|
@@ -41,7 +41,8 @@ def main(): | |
| try: | ||
| animal_func = getattr(cowsay, args.animal) | ||
| output = animal_func(message) | ||
| print(output) | ||
| if output is not None: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So can you explain in which cases the output is
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does it print |
||
| print(output) | ||
| except AttributeError: | ||
| print(f"Error: '{args.animal}' is not a valid animal.", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
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.
You can check out an alternative
get_output_stringmethod here to avoidgetattr(not the best choice to use if there is alternative - it make code more readable).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.
Noted, Thank you 🙏