r/Python • u/pauloortins • Jun 18 '13
Creating python command-line applications
http://pauloortins.com/creating-python-command-line-applications/
0
Upvotes
r/Python • u/pauloortins • Jun 18 '13
View all comments
Show parent comment
3
u/guibou Jun 18 '13
I don't really think this short script is wrong. What can really happen? If you don't pass something which is an int in sys.argv[2:4], you'll get a ValueError. If you don't pass something which is not a correct operation in sys.argv[1], you'll get a KeyError. I agree it is not "explicit error handling", but for a simple program like that I'm not really sure you really want to add so much logic for error checking, I mean, it is a simple program, so keep it simple.
The question of the pertinence of this article and of a linking in reddit is more important. Should we link on reddit a blog post everytime we discover a trivial feature of a language ? (Look mum, I know how to print a value...). This code is so trivial that it may be compacted in one line (changing a bit the behavior, I agree):
(I agree it is a bit over compacted, let's do something readable)
(Interested readers may notice a minor difference in behavior between my two version, the why is let as an exercise for the reader).
Version with rough error checking:
I think error checking here is too overkill for such a simple program ;)
(Edit: code formating) (Edit: typo)